I'm currenlty studying PRNG, and I found that there are two function, rand()
and random()
, in GNU/Linux. According to the GNU C Library section 19.8.2, this function, random()
, is just for supporting BSD compatibility. Here are my questions:
- Are these two functions identical?
- If so, where is the source code of
random()
? (I can only findrand()
in glibc)
I've tried to fix the seed parameter, and the order of the random number from rand()
and random()
are the same in my PC. So, I started to find where rand()
and random()
are implemented in glibc. Eventually, I can only found the implementation of rand()
, and the prototype of random()
in stdlib/stdlib.h (this is not official mirror).
I also try to find it in the linux source code, but still, there is no implementation of random()
. Is there anything I missed?
Edit1:
(Source code of random()
prototype)
/* These are the functions that actually do things. The `random', `srandom',
`initstate' and `setstate' functions are those from BSD Unices.
The `rand' and `srand' functions are required by the ANSI standard.
We provide both interfaces to the same random number generator. */
/* Return a random long integer between 0 and RAND_MAX inclusive. */
extern long int random (void) __THROW;
Answer:
Yes, they're identically the same in glibc. The reason why they are the same is because weak_alias (__random, random)
in random.c, which eventually use the GNU C extension called alias
.