random(3) Library Functions Manual random(3) random srandom initstate setstate - (libc -lc) #include long random(void); void srandom(unsigned int seed); char *initstate(size_t n; unsigned int seed, char state[n], size_t n); char *setstate(char *state); glibc ( feature_test_macros(7)): random() srandom() initstate() setstate(): _XOPEN_SOURCE >= 500 || /* glibc >= 2.19: */ _DEFAULT_SOURCE || /* glibc <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE random() 31 0 2^31 - 1. 16 * ((2^31) - 1). srandom() random(). srandom() . random() 1. initstate() state random(). n initstate() -- . "" n 8 32 64 128 256 . 8 . seed . setstate() random(). state initstate() setstate(). state initstate() setstate(). random() 0 (2^31) - 1. srandom() . initstate() . NULL errno . setstate() . NULL errno . EINVAL state setstate() NULL. EINVAL 8 initstate(). attributes(7). +------------+------------------------------------+--------------------+ || | | +------------+------------------------------------+--------------------+ |random() | | MT-Safe | |srandom()| | | |initstate()| | | |setstate() | | | +------------+------------------------------------+--------------------+ POSIX.1-2008. POSIX.1-2001 4.3BSD. . Numerical Recipes in C: The Art of Scientific Computing ( . . . . : 2007 ) 7 ( ). 3 ( ) . The Art of Computer Programming 2 ( ) : - 1981. random() . random_r(3) . POSIX initstate() NULL . glibc errno ( ) NULL. getrandom(2) drand48(3) rand(3) random_r(3) srand(3) 3 . . : . 6.18 8 2026 random(3)