TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: George White
from: David Noon
date: 1998-07-05 19:24:00
subject: Random number generation

In a message dated 07-04-98, George White said to David Noon about Random
number generation

Hi George,

DN>weeks ago does 32-bit PRN's, including floating point. Since this exceeds
DN>the size of a 'float' mantissa, it was typed as 'double'.

GW>Then there are the ones in SNIPPETS...

I looked at those. They have excellent periods before recurrence, but the
execution overheads are horrendous in comparison to the code I posted
implementing IBM's Power Residue algorithm.

DN>then this can introduce autocorrelations into the sequence.

GW>Even if it doesn't it reduces the length of the sequence available.

That too. Each additional call to rand() takes another number from the
sequence. Two calls to rand() halves the period; three calls takes it down
to one-third its original length, which was already too short.

DN>period is 4,294,967,296 numbers.

GW>Bit short that :-) Fortunately is isn't always true, it depends on the
GW>algorithm used by the random number generator, certainly the Borland one
GW>used in BC 3.1 has a much longer period. In the comments they claim 2^32
GW>(quite possible looking at the code), the same as yours.

The usual hint is RAND_MAX, of course, but it is not an absolute guarantee.

GW>RAND1 from snippets claims a period of 2^122...

Yes, that's one of George Marsaglia's algorithms. He posts in
sci.math.num-analysis, one of my favourite newsgroups. He is generally
regarded as _the_ leading expert in PRNG technology, perhaps aside from the
"spooks" at the NSA involved in cryptographic research.

The problem with PRNG's that have such long cycles is that multi-word
operations are used to implement them. A 122-bit seed cycle on a 32-bit CPU
makes for quite some overhead. OTOH, my code returns an unsigned long in a
few tens of nanoseconds on my 80486, and on an 80686 (P-Pro or P-II) it
would be almost instantaneous -- and the 2^32 period is acceptable for most
of my applications.

GW>Me neither, It'll be better than the compiler one anyway...

That's why I wrote it. The one in the Standard C library sucks.

Regards

Dave

___
 * MR/2 2.25 #353 * A cheap shot is a terrible thing to waste.

--- Maximus/2 3.01
* Origin: DoNoR/2,Woking UK (44-1483-717905) (2:440/4)
SEEN-BY: 396/1 622/419 632/371 633/260 267 270 371 634/397 635/506 728
SEEN-BY: 639/252 670/213 218
@PATH: 440/4 255/1 252/356 140/1 270/101 396/1 633/260 635/506 728 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.