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

Hi David,

You wrote to me:

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

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

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

True...

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

You cut the bit about the C standard library PRN period being 2^15,
which is what I was saying was a bit short...

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

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

Definitely not in the case of the Borland one. It's local storage is a
long, and it returns bits 16 to 30 as the random number.

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

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

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

Yes, looking at the code needed to implement it, blazing speed is not
it's forte...

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

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

As I said above, it does depend on the library implementation.

George

 * SLMR 2.1a * Computers eliminate spare time.

--- Maximus/2 3.01
* Origin: DoNoR/2,Woking UK (44-1483-717904) (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™.