random_r(3) Library Functions Manual random_r(3) random_r, srandom_r, initstate_r, setstate_r - C (libc, -lc) #include int random_r(struct random_data *restrict buf, int32_t *restrict result); int srandom_r(unsigned int seed, struct random_data *buf); int initstate_r(unsigned int seed, char statebuf[restrict .statelen], size_t statelen, struct random_data *restrict buf); int setstate_r(char *restrict statebuf, struct random_data *restrict buf); glibc (. feature_test_macros(7)): random_r(), srandom_r(), initstate_r(), setstate_r(): /* glibc >= 2.19: */ _DEFAULT_SOURCE || /* glibc <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE , random(3). , , . random_r() random(3), , , , buf, initstate_r(). result. srandom_r() srandom(3), , , buf initstate_r(), . The initstate_r() function is like initstate(3), except that it initializes the state in the object pointed to by buf, rather than initializing the global state variable. Before calling this function, the buf.state field must be initialized to NULL. The initstate_r() function records a pointer to the statebuf argument inside the structure pointed to by buf. Thus, statebuf should not be deallocated so long as buf is still in use. (So, statebuf should typically be allocated as a static variable, or allocated on the heap using malloc(3) or similar.) The setstate_r() function is like setstate(3), except that it modifies the state in the object pointed to by buf, rather than modifying the global state variable. state must first have been initialized using initstate_r() or be the result of a previous call of setstate_r(). All of these functions return 0 on success. On error, -1 is returned, with errno set to indicate the error. EINVAL initstate_r() 8 . EINVAL statebuf buf setstate_r() NULL. EINVAL buf result random_r() NULL. attributes(7). +----------------------------+----------------------------------------------------------+--------------------------+ | | | | +----------------------------+----------------------------------------------------------+--------------------------+ |random_r(), srandom_r(), | | MT-Safe race:buf | |initstate_r(), setstate_r() | | | +----------------------------+----------------------------------------------------------+--------------------------+ GNU. initstate_r() . , random_data , , buf.state NULL, . drand48(3), rand(3), random(3) () aereiae , Azamat Hackimov , Dmitriy S. Seregin , Katrin Kutepova , Lockal , Yuri Kozlov , ; GNU (GNU General Public License - GPL, 3 ) , - . - , , () () () . Linux man-pages 6.18 8 2026 . random_r(3)