1 .\" Copyright 2008 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
26 .TH RANDOM_R 3 2014-03-25 "GNU" "Linux Programmer's Manual"
28 random_r, srandom_r, initstate_r, setstate_r \- reentrant
29 random number generator
32 .B #include <stdlib.h>
34 .BI "int random_r(struct random_data *" buf ", int32_t *" result );
36 .BI "int srandom_r(unsigned int " seed ", struct random_data *" buf );
38 .BI "int initstate_r(unsigned int " seed ", char *" statebuf ,
39 .BI " size_t " statelen ", struct random_data *" buf );
41 .BI "int setstate_r(char *" statebuf ", struct random_data *" buf );
45 Feature Test Macro Requirements for glibc (see
46 .BR feature_test_macros (7)):
55 _SVID_SOURCE || _BSD_SOURCE
59 These functions are the reentrant equivalents
60 of the functions described in
62 They are suitable for use in multithreaded programs where each thread
63 needs to obtain an independent, reproducible sequence of random numbers.
69 except that instead of using state information maintained
71 it uses the state information in the argument pointed to by
73 The generated random number is returned in the argument
80 except that it initializes the seed for the random number generator
81 whose state is maintained in the object pointed to by
83 instead of the seed associated with the global state variable.
89 except that it initializes the state in the object pointed to by
91 rather than initializing the global state variable.
97 except that it modifies the state in the object pointer to by
99 rather than modifying the global state variable.
101 All of these functions return 0 on success.
102 On error, \-1 is returned, with
104 set to indicate the cause of the error.
108 A state array of less than 8 bytes was specified to
129 .SS Multithreading (see pthreads(7))
136 functions are thread-safe.
138 These functions are nonstandard glibc extensions.
139 .\" These functions appear to be on Tru64, but don't seem to be on
140 .\" Solaris, HP-UX, or FreeBSD.