PRNG Algorithm for RAN()

  • Thread starter John Schutkeker
  • Start date
J

John Schutkeker

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?
 
M

Mike Wahler

John Schutkeker said:
Does anybody know what pseudo-random number generator was used to implement
the RAN() function in the C standard math library?

There isn't a single one. Each implementation is free
to use its own version, as long as its behavior meets
specifications.
Knuth couldn't have
gone so far as to implement a quadratic congruential method, right?

I don't know, why not look it up?
Is it
yet another implementation of the much reviled RANDU?

The C standard does not specify which algorithm be used
by the standard library function 'rand()'.

-Mike
 
R

Richard Bos

John Schutkeker said:
Does anybody know what pseudo-random number generator was used to implement
the RAN() function in the C standard math library?

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 couldn't have
gone so far as to implement a quadratic congruential method, right?

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
 
M

Micah Cowan

John Schutkeker said:
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?

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
 
J

John Schutkeker

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."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top