1RANDOM_R(3)                Linux Programmer's Manual               RANDOM_R(3)
2
3
4

NAME

6       random_r,  srandom_r, initstate_r, setstate_r - reentrant random number
7       generator
8

SYNOPSIS

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():
23           _SVID_SOURCE || _BSD_SOURCE
24

DESCRIPTION

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

RETURN VALUE

50       All  of these functions return 0 on success.  On error, -1 is returned,
51       with errno set to indicate the cause of the error.
52

ERRORS

54       EINVAL A state array of less  than  8  bytes  was  specified  to  init‐
55              state_r().
56
57       EINVAL The statebuf or buf argument to setstate_r() was NULL.
58
59       EINVAL The buf or result argument to random_r() was NULL.
60

CONFORMING TO

62       These functions are nonstandard glibc extensions.
63

SEE ALSO

65       drand48(3), rand(3), random(3)
66

COLOPHON

68       This  page  is  part of release 3.53 of the Linux man-pages project.  A
69       description of the project, and information about reporting  bugs,  can
70       be found at http://www.kernel.org/doc/man-pages/.
71
72
73
74GNU                               2013-04-19                       RANDOM_R(3)
Impressum