1RANDOM_R(3) Linux Programmer's Manual RANDOM_R(3)
2
3
4
6 random_r, srandom_r, initstate_r, setstate_r - reentrant random number
7 generator
8
10 #include <stdlib.h>
11
12 int random_r(struct random_data *buf, int32_t *result);
13
14 int srandom_r(unsigned int seed, struct random_data *buf);
15
16 int initstate_r(unsigned int seed, char *statebuf,
17 size_t statelen, struct random_data *buf);
18 int setstate_r(char *statebuf, struct random_data *buf);
19
20 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
21
22 random_r(), srandom_r(), initstate_r(), setstate_r(): _SVID_SOURCE ||
23 _BSD_SOURCE
24
26 These functions are the reentrant equivalents of the functions
27 described in random(3). They are suitable for use in multithreaded
28 programs where each thread needs to obtain an independent, reproducible
29 sequence of random numbers.
30
31 The random_r() function is like random(3), except that instead of using
32 state information maintained in a global variable, it uses the state
33 information in the argument pointed to by buf. The generated random
34 number is returned in the argument result.
35
36 The srandom_r() function is like srandom(3), except that it initializes
37 the seed for the random number generator whose state is maintained in
38 the object pointed to by buf, instead of the seed associated with the
39 global state variable.
40
41 The initstate_r() function is like initstate(3) except that it initial‐
42 izes the state in the object pointed to by buf, rather than initializ‐
43 ing the global state variable.
44
45 The setstate_r() function is like setstate(3) except that it modifies
46 the state in the object pointer to by buf, rather than modifying the
47 global state variable.
48
50 All of these functions return 0 on success, or -1 on error.
51
53 EINVAL A state array of less than 8 bytes was specified to init‐
54 state_r().
55
56 EINVAL The statebuf or buf argument to setstate_r() was NULL.
57
58 EINVAL The buf or result argument to random_r() was NULL.
59
61 These functions are non-standard glibc extensions.
62
64 drand48(3), rand(3), random(3)
65
67 This page is part of release 3.22 of the Linux man-pages project. A
68 description of the project, and information about reporting bugs, can
69 be found at http://www.kernel.org/doc/man-pages/.
70
71
72
73GNU 2008-03-07 RANDOM_R(3)