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-08 05:45:34 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!snoopy.risq.qc.ca!chi1.webusenet.com!c03.atl99!news.webusenet.com!telocity-west!DIRECTV!sn-xit-03!sn-xit-01!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "David C. Hoos" Newsgroups: comp.lang.ada Subject: Re: Pseudo Random coding problem Date: Wed, 8 Jan 2003 07:45:33 -0600 Organization: Posted via Supernews, http://www.supernews.com Message-ID: References: <3e1b633f.3280604@news.demon.co.uk> <%xLS9.675327$NH2.47318@sccrnsc01> <3e1c00e7.634181@news.demon.co.uk> X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Complaints-To: abuse@supernews.com Xref: archiver1.google.com comp.lang.ada:32747 Date: 2003-01-08T07:45:33-06:00 List-Id: "Brian A Crawford" wrote in message news:3e1c00e7.634181@news.demon.co.uk... > According to the replies so far I seem to be producing two streams. > How do I produce and check one only. You are generating only one stream (because you are using only one generator, initialized only once). However, you are sampling the stream from two points in your code, thus creating two "substreams," as it were. So, the key is to assign the value of the draw to a variable, and then make whatever tests you wish on that one draw, before drawing again. Each call to Random_50.Random is a "draw." Here's a refinement of your program which shows a better way to test for randomness: 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; Draw : Randomrange; Occurrence_Array : array (Randomrange) of Natural := (others => 0); Minimum : Natural := Natural'Last; Maximum : Natural := Natural'First; begin -- random_numbers Random_50.Reset (Gen => G); -- starts g from time of day clock for Row in 1 .. 100_000_000 loop Draw := Random_50.Random (Gen => G); Occurrence_Array (Draw) := Occurrence_Array (Draw) + 1; end loop; for O in Occurrence_Array'Range loop Ada.Text_IO.Put_Line ("The value" & Randomrange'Image (O) & " occurred" & Natural'Image (Occurrence_Array (O)) & " times."); Minimum := Natural'Min (Minimum, Occurrence_Array (O)); Maximum := Natural'Max (Maximum, Occurrence_Array (O)); end loop; Ada.Text_IO.Put_Line ("The minimum number of occurrences of any one value was" & Natural'Image (Minimum)); Ada.Text_IO.Put_Line ("The maximum number of occurrences of any one value was" & Natural'Image (Maximum)); end Random_Numbers; The last two lines of the program output from two runs were: Run 1: The minimum number of occurrences of any one value was 1995646 The maximum number of occurrences of any one value was 2003366 Run 2: The minimum number of occurrences of any one value was 1996974 The maximum number of occurrences of any one value was 2003924