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