PRNG Algorithm for RAN()

Discussion in 'C Programming' started by John Schutkeker, Jul 4, 2003.

1. John SchutkekerGuest

Does anybody know what pseudo-random number generator was used to implement
the RAN() function in the C standard math library? Knuth couldn't have
gone so far as to implement a quadratic congruential method, right? Is it
yet another implementation of the much reviled RANDU?

John Schutkeker, Jul 4, 2003

2. Mike WahlerGuest

There isn't a single one. Each implementation is free
to use its own version, as long as its behavior meets
specifications.
I don't know, why not look it up?
The C standard does not specify which algorithm be used
by the standard library function 'rand()'.

-Mike

Mike Wahler, Jul 4, 2003

3. Richard BosGuest

There is no RAN() function in the C library (and if there were, that
all-caps name would be a bad idea). The Standard RNG function is called
rand(). rand() is not in the math library, nor in the maths headers, but
Knuth has nothing to do with the ISO C Standard library (unless he is on
the ISO C Committee, which I think he isn't, BICBW), and he certainly
has not implemented anything that can be called "the" Standard library.

All the Standard requires is that
- rand() returns a sequence of PRNs, between 0 to RAND_MAX inclusive;
- no library function shall call rand() (as far as the user can detect);
- RAND_MAX is at least 32767;
- srand() can be used to initialise rand()'s seed.

Nothing else is required. An example is given as to how rand() _could_
be implemented, but that's all it is: an example.

Richard

Richard Bos, Jul 4, 2003
4. Micah CowanGuest

Hm... well, first of all, neither RAN() nor RANDU() are in the C
standard math library. Second, Donald Knuth had nothing whatsoever to
do with the creation of the standard library, though it's conceivable
that he has written one of his own.

I would be less surprised if you had meant something like "the math
library Knuth wrote in C". I still don't know to what you would be
referring, but I don't doubt that he has written math libraries in C.

But none of this is really topical in a newsgroup which discusses only
the ISO C programming language, now is it?

-Micah

Micah Cowan, Jul 5, 2003
5. John SchutkekerGuest

Did Ritchie, or whoever wrote this routine, ever publish a justification
for the constant "1103515245." I guess the whole trick to writing a good
LCG is to find the best possible value of that constant. There's obviously
nothing special about the built in seed, "12345."

John Schutkeker, Jul 6, 2003