comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <rieachus@attbi.com>
Subject: Re: Random Number Generator Problem
Date: Fri, 25 Jul 2003 15:34:16 GMT
Date: 2003-07-25T15:34:16+00:00	[thread overview]
Message-ID: <3F214DF6.6010102@attbi.com> (raw)
In-Reply-To: 30c81431.0307250634.77148b62@posting.google.com

Brien wrote:

> When I run this code, i get 9,233,........,808 (which is 2**63) as
> about half of my results.

There are two problems here.  The first, which you should definitely 
report to ACT, is that the code for the discrete generator uses 
(long_)integers.  Obviously 2**64 > 2**63, so there is a problem here. 
The fix is that when generating values of this type, the bounds should 
be Long_Integer'First and Long_Integer'Last, not 0 and Max_Binary_Modulus.

There is a line in the algorithm which folds out of range values into 
the largest possible value.  For normal ranges, this line preserves the 
unbiased nature of the results.  But in this case, half the results 
(generated as Long_Floats) will be out of range for the (intermediate) 
Long_Integer type.

The second problem is that you may be trying to accomplish something 
that the Ada RM does not promise.  The algorithm as written will 
generate many more than 2**32 values. (About 2**50 but I'd have to dig 
out my documentation to get the exact number of possible values.)  If 
you really need the possibility of 2**64 unbiased values, there are few, 
if any, RNGs outside of cryptography that will do what you want.

The GNAT generator IS a cryptographic generator with a few cheats to 
make it highly efficient--but not useful for cryptographic purposes.  I 
just haven't gotten around to generating a version of the algorithm that 
will provide 2**64 unbiased values.  If you haven't guessed, this will 
take several days of CPU time (in the background on this machine is 
fine) to find the necessary constants, plus modifications to the 
generator code.

So, how many values do you really need?  And are there other 
characteristics that you need?  It is probably the case that I can give 
you some code that takes twice as long as the GNAT generator and does 
what you need.  (Notice though that it will take years to generate all 
of the possible values for the current generator, even on today's 
fastest CPUs.  So I thought I had a few years before this issue became 
urgent.)

-- 

                                                        Robert I. Eachus

�In an ally, considerations of house, clan, planet, race are 
insignificant beside two prime questions, which are: 1. Can he shoot? 2. 
Will he aim at your enemy?� -- from the Laiden novels by Sharon Lee and 
Steve Miller.




  reply	other threads:[~2003-07-25 15:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-25 14:34 Random Number Generator Problem Brien
2003-07-25 15:34 ` Robert I. Eachus [this message]
2003-07-28 13:14   ` Brien
2003-07-25 17:06 ` Anisimkov
2003-07-25 18:05   ` Robert I. Eachus
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox