1 .\" Copyright 2008 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
24 .TH RANDOM_R 3 2008-03-07 "GNU" "Linux Programmer's Manual"
26 random_r, srandom_r, initstate_r, setstate_r \- reentrant
27 random number generator
30 .B #include <stdlib.h>
32 .BI "int random_r(struct random_data *" buf ", int32_t *" result );
34 .BI "int srandom_r(unsigned int " seed ", struct random_data *" buf );
36 .BI "int initstate_r(unsigned int " seed ", char *" statebuf ,
37 .BI " size_t " statelen ", struct random_data *" buf );
39 .BI "int setstate_r(char *" statebuf ", struct random_data *" buf );
43 Feature Test Macro Requirements for glibc (see
44 .BR feature_test_macros (7)):
52 _SVID_SOURCE || _BSD_SOURCE
55 These functions are the reentrant equivalents
56 of the functions described in
58 They are suitable for use in multithreaded programs where each thread
59 needs to obtain an independent, reproducible sequence of random numbers.
65 except that instead of using state information maintained
67 it uses the state information in the argument pointed to by
69 The generated random number is returned in the argument
76 except that it initializes the seed for the random number generator
77 whose state is maintained in the object pointed to by
79 instead of the seed associated with the global state variable.
85 except that it initializes the state in the object pointed to by
87 rather than initializing the global state variable.
93 except that it modifies the state in the object pointer to by
95 rather than modifying the global state variable.
97 All of these functions return 0 on success, or \-1 on error.
101 A state array of less than 8 bytes was specified to
122 These functions are nonstandard glibc extensions.
123 .\" These functions appear to be on Tru64, but don't seem to be on
124 .\" Solaris, HP-UX, or FreeBSD.