I have read in several places ("Numerical Recipes", Knuth's books, etc.) the rand() facility is not a very good random number generator, because it is often poorly implemented. So I am planning to write my own implementation, but before that I would like to see the "native" rand() implementation on my computer (I have a Mac Intel with os 10.5 and I use gcc), how do I do that?
I looked in /usr/include/stdlib.h, but it just declares it:
K&R show the following standard implementation:
unsigned long int next = 1;
/* rand: return pseudo-random integer on 0..32767 */
next = next * 1103515245 + 12345;
return (unsigned int)(next/65536) % 32768;
/* srand: set seed for rand() */
void srand(unsigned int seed)
next = seed;
But implementations can vary from that. How can I check whether I am using that one when calling rand(). There should be a file (compiled or not) with the implementation, no? Where is it and how can I read it if it is compiled?