From: mcc@tyrolia.cs.princeton.edu (Martin C. Carlisle)
Subject: Re: Random Number problems
Date: 1997/10/01
Date: 1997-10-01T00:00:00+00:00 [thread overview]
Message-ID: <60tsk9$5gg$1@cnn.Princeton.EDU> (raw)
In-Reply-To: 3431B598.41C6@activist.com
In article <3431B598.41C6@activist.com>,
David Muhammad <guru@activist.com> wrote:
>>I am trying to write a function that will
> use a Random Number Generator and then return a random value between
>1 and 52. I have written the Random Number Generator function but how
>do I tell the compiler to select a number between 1 and 52.
>
>a) declare a subtype
> subtype pseudorand is range 1..52
>b) Call my randomnumber from function Rand_Num
>c) NOw somehow convert some "Number" to a range between 1 and 52.
>I am stuck ??
Most people would instead use the very nice built-in random number
generator.
E.g.
package my_random is new Ada.Numerics.Discrete_Random(pseudorand);
g : my_random.generator;
x : pseudorand;
begin
my_random.reset(g);
x := my_random.random(g);
For more info, see LRM A.5.2, Barnes p. 54, Feldman pp 320-322,
Cohen p. 93
If you insist on using your own, you want to use mod.
--Martin
--
Martin C. Carlisle, Computer Science, US Air Force Academy
mcc@cs.usafa.af.mil, http://www.usafa.af.mil/dfcs/bios/carlisle.html
DISCLAIMER: This content in no way reflects the opinions, standard or
policy of the US Air Force Academy or the United States Government.
next prev parent reply other threads:[~1997-10-01 0:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-09-30 0:00 Stream_Access value valid across Close/Open? Dale Stanbrough
1997-09-30 0:00 ` Random Number problems David Muhammad
1997-10-01 0:00 ` Geert Bosch
1997-10-01 0:00 ` Martin C. Carlisle [this message]
-- strict thread matches above, loose matches on Subject: below --
1997-10-01 0:00 John Herro
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox