OSDN Git Service

(split) LDP: Change Makefile to stamp-based compilation
[linuxjm/LDP_man-pages.git] / original / man3 / random_r.3
1 .\" Copyright 2008 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
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.
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.
23 .\" %%%LICENSE_END
24 .\"
25 .\"
26 .TH RANDOM_R 3  2008-03-07 "GNU" "Linux Programmer's Manual"
27 .SH NAME
28 random_r, srandom_r, initstate_r, setstate_r \- reentrant
29 random number generator
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
45 Feature 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 ():
54 .RS 4
55 _SVID_SOURCE || _BSD_SOURCE
56 .RE
57 .ad b
58 .SH DESCRIPTION
59 These functions are the reentrant equivalents
60 of the functions described in
61 .BR random (3).
62 They are suitable for use in multithreaded programs where each thread
63 needs to obtain an independent, reproducible sequence of random numbers.
64
65 The
66 .BR random_r ()
67 function is like
68 .BR random (3),
69 except that instead of using state information maintained
70 in a global variable,
71 it uses the state information in the argument pointed to by
72 .IR buf .
73 The generated random number is returned in the argument
74 .IR result .
75
76 The
77 .BR srandom_r ()
78 function is like
79 .BR srandom (3),
80 except that it initializes the seed for the random number generator
81 whose state is maintained in the object pointed to by
82 .IR buf ,
83 instead of the seed associated with the global state variable.
84
85 The
86 .BR initstate_r ()
87 function is like
88 .BR initstate (3)
89 except that it initializes the state in the object pointed to by
90 .IR buf ,
91 rather than initializing the global state variable.
92
93 The
94 .BR setstate_r ()
95 function is like
96 .BR setstate (3)
97 except that it modifies the state in the object pointer to by
98 .IR buf ,
99 rather than modifying the global state variable.
100 .SH RETURN VALUE
101 All of these functions return 0 on success, or \-1 on error.
102 .SH ERRORS
103 .TP
104 .B EINVAL
105 A state array of less than 8 bytes was specified to
106 .BR initstate_r ().
107 .TP
108 .B EINVAL
109 The
110 .I statebuf
111 or
112 .I buf
113 argument to
114 .BR setstate_r ()
115 was NULL.
116 .TP
117 .B EINVAL
118 The
119 .I buf
120 or
121 .I result
122 argument to
123 .BR random_r ()
124 was NULL.
125 .SH CONFORMING TO
126 These functions are nonstandard glibc extensions.
127 .\" These functions appear to be on Tru64, but don't seem to be on
128 .\" Solaris, HP-UX, or FreeBSD.
129 .SH SEE ALSO
130 .BR drand48 (3),
131 .BR rand (3),
132 .BR random (3)