From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "J-P. Rosen" Newsgroups: comp.lang.ada Subject: Re: Ada.Numerics.Float_Random.Generator question Date: Sat, 17 Sep 2016 22:09:59 +0200 Organization: A noiseless patient Spider Message-ID: References: <5db08ea5-c088-4d16-9d88-d058e4bc48df@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Date: Sat, 17 Sep 2016 20:09:56 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="8f584e3d49c8e3b0a08acc13e4029db4"; logging-data="840"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18CHfkMQGh/h8Cr/BnqDxDY" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 In-Reply-To: <5db08ea5-c088-4d16-9d88-d058e4bc48df@googlegroups.com> Cancel-Lock: sha1:Zh8tQuvrwit7CEpP3DZBosnc3ws= Xref: news.eternal-september.org comp.lang.ada:31801 Date: 2016-09-17T22:09:59+02:00 List-Id: Le 17/09/2016 à 21:40, Andrew Shvets a écrit : > This works. However, as I'm now looking into the > Ada.Numerics.Discrete_Random package, I've noticed that it can > generate a random value based on the type that is passed in. This > appeals to me and I'd like to do the same for a custom float type > (say I want the delta to be 0.01.) Beware! Random number generators are tricky. It took megabytes of discussion to come to the conclusion that it was not possible to make a proper discrete generator out of a floating point generator... Now, if you want a delta of 0.01, it looks more like a fixed point than a floating point. This can be easily achieved by instantiating discrete_random on an integer type with the proper number of values and then multiplying by 0.01. -- J-P. Rosen Adalog 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00 http://www.adalog.fr