I'm looking to generate large, non-negative integer random values on a POSIX system. I've found 2 possible functions that fit the bill, and their respective initializers:
#include <stdlib.h>
long int random(void);
void srandom(unsigned int seed);
CONFORMING TO
4.3BSD, POSIX.1-2001.
// and
long int lrand48(void);
void srand48(long int seedval);
CONFORMING TO
SVr4, POSIX.1-2001.
long int
vs. unsigned int
)?Use nrand48
, it has the same range as lrand48
and receives a pointer to an array used as a seed. making this thread local will ensure thread safety. (as a side note, it appears the glibc implementation may have some issues, see http://evanjones.ca/random-thread-safe.html for more information, this page also contains a nice summary of thread safe random number generation functions)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With