comp.lang.ada
 help / color / mirror / Atom feed
From: Geert Bosch <geert@gonzo.sun3.iaf.nl>
Subject: Re: Random Number problems
Date: 1997/10/01
Date: 1997-10-01T00:00:00+00:00	[thread overview]
Message-ID: <60tprq$lci$1@gonzo.sun3.iaf.nl> (raw)
In-Reply-To: 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 ??

A quick quote from the nice RM:

  50    (16) A given implementation of the Random function in
	Numerics.Float_Random may or may not be capable of delivering
	the values 0.0 or 1.0. Portable applications should assume
	that these values, or values sufficiently close to them to
	behave indistinguishably from them, can occur.  If a sequence
	of random integers from some fixed range is needed, the
	application should use the Random function in an appropriate
	instantiation of Numerics.Discrete_Random, rather than
	transforming the result of the Random function in
	Numerics.Float_Random.  However, some applications with
	unusual requirements, such as for a sequence of random
	integers each drawn from a different range, will find it
	more convenient to transform the result of the floating
	point Random function.  For M>=1, the expression

        51       Integer(Float(M) * Random(G)) mod M
        

  52    transforms the result of Random(G) to an integer uniformly
	distributed over the range 0 .. M-1; it is valid even if
	Random delivers 0.0 or 1.0.  Each value of the result range
	is possible, provided that M is not too large.  Exponentially
	distributed (floating point) random numbers with mean and
	standard deviation 1.0 can be obtained by the transformation

        53       -Log(Random(G) + Float'Model_Small))
        

  54    where Log comes from Numerics.Elementary_Functions (see
	A.5.1); in this expression, the addition of Float'Model_Small
	avoids the exception that would be raised were Log to be
	given the value zero, without affecting the result (in most
	implementations) when Random returns a nonzero value.





  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   ` Martin C. Carlisle
1997-10-01  0:00   ` Geert Bosch [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