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=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,47a3564e17a59a63 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-01-07 20:08:19 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: starritt@rlmsystems.com.au (Andy Starritt) Newsgroups: comp.lang.ada Subject: Re: Pseudo Random coding problem Date: 7 Jan 2003 20:08:18 -0800 Organization: http://groups.google.com/ Message-ID: <71f5f0c7.0301072008.61d508b2@posting.google.com> References: <3e1b633f.3280604@news.demon.co.uk> NNTP-Posting-Host: 203.14.96.10 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1041998899 28762 127.0.0.1 (8 Jan 2003 04:08:19 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 8 Jan 2003 04:08:19 GMT Xref: archiver1.google.com comp.lang.ada:32722 Date: 2003-01-08T04:08:19+00:00 List-Id: brianc@billybob.demon.co.uk (Brian A Crawford) wrote in message news:<3e1b633f.3280604@news.demon.co.uk>... > I am trying to start a small programming project that will output > pseudo-random numbers. > The program looks at the numbers produced and if that number equals a > predetermined value (20 in the case in the test program below) the > program will then catch this fact and perform a number of loops and > counts etc. > > However I've fallen at the first hurdle. I've heavily borrowed code > from Ada95 by Feldman/Koffman (thankyou!) and find that the program > sometimes sees the value 20 and on other occasions doesn't. > It's very tempermental. Because your program loops only 15 times, and the random number range is 1 to 50, I would expect 20 to turn up (on average) approx 30% of the time. It is supposed to be random after all ;-) > The code is below. Ive definitely missed something. > ________________________________________________ > > WITH Ada.Text_IO; > WITH Ada.Integer_Text_IO; > WITH Ada.Float_Text_IO; > WITH Ada.Numerics.Discrete_Random; > > procedure Random_Numbers is > > SUBTYPE RandomRange IS positive RANGE 1..50; > > PACKAGE Random_50 IS NEW Ada.Numerics.Discrete_Random > (Result_Subtype => RandomRange); > > > G: Random_50.Generator; > > BEGIN -- Random_Numbers > > Random_50.Reset (Gen => G); -- starts G from time of day clock > > for row in 1..15 loop > > Ada.Integer_Text_IO.Put > (Item => Random_50.Random(Gen => G), Width => 8); > > if Random_50.Random(Gen => G) = 20 then > Ada.Text_io.put (Item => "Random Number is equal to > Twenty"); > > Ada.text_io.new_line; > end if; > Ada.text_io.new_line; > > end loop; > > END Random_Numbers; > _______________________________________________________