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,34e3e7f96ab2aa27,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-03-02 00:31:26 PST Newsgroups: comp.lang.ada Path: nntp.gmd.de!stern.fokus.gmd.de!ceres.fokus.gmd.de!zib-berlin.de!fu-berlin.de!zrz.TU-Berlin.DE!netmbx.de!unlisys!news.maz.net!pipex!howland.reston.ans.net!ix.netcom.com!netcom.com!dmarshal From: dmarshal@netcom.com (Dave Marshall) Subject: Re: Random numbers in Gnat Message-ID: Organization: NETCOM On-line Communication Services (408 261-4700 guest) References: <3j2q9t$s3n@solar.Armstrong.EDU> Date: Thu, 2 Mar 1995 08:31:26 GMT Sender: dmarshal@netcom9.netcom.com Date: 1995-03-02T08:31:26+00:00 List-Id: ab@captblood.armstrong.edu () writes: >I cannot find any discussion of the use of random() procedure Please, humor me. Don't put parentheses in when it's not C. >in gnat-2.03 Unix version for SunOS 4.1.3. The only information >that I found is in file a-numran.ads, and as the following >shows I must have misunderstood the intent and use of the objects >in that file. Always consult the LRM for definitive discussion. Read the Rationale, too, for a more narrative-type approach. >Here is a little test that I've concocted: > with text_io; use text_io; > with ada.numerics.random; use ada.numerics.random; I hate "use"s. Thank God for "use types." Whoever is getting royalties on "renames" is going to become poor very soon. > procedure randtest is > package int_io is new integer_io(integer); use int_io; I hate Text_IO.Integer_IO, too. > rand_state: state:= make_state; > -- return random number in 0..up_bound > function my_random(up_bound: integer) return integer is > r: Uniformly_Distributed; > begin > random( rand_state, r); > return integer(r*float(up_bound)); > end my_random; > begin > for i in 1..10 loop > put(my_random(1000)); new_line; > end loop; > end randtest; This is far too complicated. By the way, my copy of the latest and greatest RM just doesn't mention Ada.Numerics.Random. I see Ada.Numerics.Discrete_Random and Ada.Numerics.Float_Random. >The program prints out only zeros rather than 10 random numbers in the >0..1000 range. I dislike the use of the global rand_state variable. >However using it as a parameter is no better either. Indeed, why >should one be bothered with this quantity anyway? (In C one >just seeds the generator, and then calls the random() as a >parameterless function, why not here?) Because different tasks may want different seeds. >I'll appreciate your discussion as to how the random number >generator should be used. Pointers to some documentation/discussion >of the objects in a-numran.ads would also be helpful. Here's my program that attempts to do the same thing. with Text_IO; with Ada.Numerics.Discrete_Random; type Some_Numbers is range 0 .. 1_000; package Some_Random is new Ada.Numerics.Discrete_Random(Some_Numbers); Some_Generator : Some_Random.Generator; begin Some_Random.Reset(Some_Generator); for I in 1 .. 10 loop Text_IO.Put(Some_Numbers'Image(Some_Random.Random(Some_Generator))); end loop; end Rand_Test; >Dr. A.Bykat >Fuller E. Callaway Professor -- Dave Marshall dmarshal@netcom.com