]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/random_r.3
intro.1, _exit.2, access.2, alarm.2, alloc_hugepages.2, arch_prctl.2, bind.2, chdir...
[thirdparty/man-pages.git] / man3 / random_r.3
CommitLineData
ceb141cf
MK
1.\" Copyright 2008 Michael Kerrisk <mtk.manpages@gmail.com>
2.\"
4b72fb64 3.\" %%%LICENSE_START(verbatim)
ceb141cf
MK
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.
7.\"
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.
12.\"
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
19.\" professionally.
20.\"
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 23.\" %%%LICENSE_END
ceb141cf
MK
24.\"
25.\"
26.TH RANDOM_R 3 2008-03-07 "GNU" "Linux Programmer's Manual"
27.SH NAME
b75101c3 28random_r, srandom_r, initstate_r, setstate_r \- reentrant
ceb141cf 29random number generator
ceb141cf
MK
30.SH SYNOPSIS
31.nf
32.B #include <stdlib.h>
33.sp
34.BI "int random_r(struct random_data *" buf ", int32_t *" result );
35
36.BI "int srandom_r(unsigned int " seed ", struct random_data *" buf );
37
38.BI "int initstate_r(unsigned int " seed ", char *" statebuf ,
39.BI " size_t " statelen ", struct random_data *" buf );
40.br
41.BI "int setstate_r(char *" statebuf ", struct random_data *" buf );
42.fi
43.sp
44.in -4n
45Feature Test Macro Requirements for glibc (see
46.BR feature_test_macros (7)):
47.in
48.sp
49.ad l
50.BR random_r (),
51.BR srandom_r (),
52.BR initstate_r (),
53.BR setstate_r ():
2565afda 54.RS 4
ceb141cf 55_SVID_SOURCE || _BSD_SOURCE
2565afda 56.RE
ceb141cf
MK
57.ad b
58.SH DESCRIPTION
59These functions are the reentrant equivalents
60of the functions described in
61.BR random (3).
62They are suitable for use in multithreaded programs where each thread
63needs to obtain an independent, reproducible sequence of random numbers.
64
65The
66.BR random_r ()
67function is like
68.BR random (3),
69except that instead of using state information maintained
70in a global variable,
71it uses the state information in the argument pointed to by
72.IR buf .
73The generated random number is returned in the argument
74.IR result .
75
76The
77.BR srandom_r ()
78function is like
79.BR srandom (3),
80except that it initializes the seed for the random number generator
81whose state is maintained in the object pointed to by
82.IR buf ,
83instead of the seed associated with the global state variable.
84
85The
86.BR initstate_r ()
87function is like
88.BR initstate (3)
89except that it initializes the state in the object pointed to by
90.IR buf ,
91rather than initializing the global state variable.
92
93The
94.BR setstate_r ()
95function is like
96.BR setstate (3)
97except that it modifies the state in the object pointer to by
98.IR buf ,
99rather than modifying the global state variable.
47297adb 100.SH RETURN VALUE
ceb141cf
MK
101All of these functions return 0 on success, or \-1 on error.
102.SH ERRORS
103.TP
104.B EINVAL
105A state array of less than 8 bytes was specified to
106.BR initstate_r ().
107.TP
108.B EINVAL
109The
110.I statebuf
111or
112.I buf
113argument to
114.BR setstate_r ()
115was NULL.
116.TP
117.B EINVAL
118The
119.I buf
120or
121.I result
122argument to
123.BR random_r ()
124was NULL.
47297adb 125.SH CONFORMING TO
c8f2dd47 126These functions are nonstandard glibc extensions.
b75101c3 127.\" These functions appear to be on Tru64, but don't seem to be on
ceb141cf 128.\" Solaris, HP-UX, or FreeBSD.
47297adb 129.SH SEE ALSO
ceb141cf
MK
130.BR drand48 (3),
131.BR rand (3),
132.BR random (3)