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: border2.nntp.dca1.giganews.com!buffer2.nntp.dca1.giganews.com!border2.nntp.dca3.giganews.com!backlog4.nntp.dca3.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nac.net!feeder.erje.net!eu.feeder.erje.net!news-2.dfn.de!news.dfn.de!news.uni-weimar.de!medsec1.medien.uni-weimar.de!lucks From: Stefan.Lucks@uni-weimar.de Newsgroups: comp.lang.ada Subject: Re: Lotto simulation Date: Mon, 16 Jun 2014 13:15:26 +0200 Organization: Bauhaus-Universitaet Weimar Message-ID: References: <77cc4476-8c57-481b-afb9-8f53f8b16e37@googlegroups.com> NNTP-Posting-Host: medsec1.medien.uni-weimar.de Mime-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="8323329-254637024-1402917327=:6265" X-Trace: pinkpiglet.scc.uni-weimar.de 1402917273 25151 141.54.178.228 (16 Jun 2014 11:14:33 GMT) X-Complaints-To: news@pinkpiglet.scc.uni-weimar.de NNTP-Posting-Date: Mon, 16 Jun 2014 11:14:33 +0000 (UTC) X-X-Sender: lucks@debian In-Reply-To: User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) X-Original-Bytes: 4318 Xref: number.nntp.dca.giganews.com comp.lang.ada:186958 Date: 2014-06-16T13:15:26+02:00 List-Id: This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-254637024-1402917327=:6265 Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE On Mon, 16 Jun 2014, J-P. Rosen wrote: >> but mathematically, given a uniformly >> distributed real number F between 0.0 and 1.0, one can get a uniformly >> distributed discrete D between Low and high: D :=3D Truncate(Low + F * >> (High-Low + 1)). > I think it all depends on the definition of "uniformly distributed". If > it is uniformly distributed among all representable floating point > numbers (which you get if you take an integer random number and > unchecked-convert it to Float), you'll get many more values below 0.5 > than above (since the range 0.5..1.0 is represented with only one value > of the exponent). Well, do you think the Annotated Reference Manual=20 needs a=20 clarification? It explicitely tells A sufficiently long sequence of random numbers obtained by successive calls to Random is approximately uniformly distributed over the range of the result subtype. From=20my point of view, "uniformly distributed over the range of the resul= t=20 subtype" would seem to imply values > 0.5 to be as often as values < 0.5. In fact, I would claim that any random generator, choosing floats between= =20 0.0 and 1.0 with a significant bias towards 0.0 or 1.0 would be plain=20 stupid and worse than useless, and a standard which allows that, would=20 need urgent repair! Fortunately, my Ada compiler (gnat) is not such stupid and behaves as I=20 had expected: with Ada.Text_IO, Ada.Numerics.Float_Random, Ada.Command_Line; procedure Test_Rnd is package ANFR renames Ada.Numerics.Float_Random; Gen: ANFR.Generator; High: Natural :=3D 0; Sample_Size: constant Natural :=3D Natural'Value(Ada.Command_Line.Argum= ent(1)); begin ANFR.Reset(Gen); for I in 1 .. Sample_Size loop if ANFR.Random(Gen) > 0.5 then =09 High :=3D High + 1; end if; end loop; Ada.Text_IO.Put_Line(Integer'Image(High) &" /"& Integer'Image(Sample_Si= ze)); end Test_Rnd; Compiling and running the above program indicates an even distribution of= =20 values > 0.5 and <=3D 0.5 (i.e., there is no statistically significant=20 bias): $ ./test_rnd 100000000 49999482 / 100000000 $ ./test_rnd 1000000000 499991845 / 1000000000 Note that the results are biased towards 0.0, but the bias is=20 statistically insignificant. (It would be statistically strange, indeed,=20 if *exactly* half of the random values would be below 0.5, and the other=20 half would be above.) So long ------ I love the taste of Cryptanalysis in the morning! ------ --Stefan.Lucks (at) uni-weimar.de, Bauhaus-Universit=E4t Weimar, Germany-- --8323329-254637024-1402917327=:6265--