OSDN Git Service

(split) Import translated manuals from JM CVS Repository.
[linuxjm/LDP_man-pages.git] / original / man3 / random_r.3
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
26 random_r, srandom_r, initstate_r, setstate_r \- reentrant
27 random number generator
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
43 Feature 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
55 These functions are the reentrant equivalents
56 of the functions described in
57 .BR random (3).
58 They are suitable for use in multithreaded programs where each thread
59 needs to obtain an independent, reproducible sequence of random numbers.
60
61 The
62 .BR random_r ()
63 function is like
64 .BR random (3),
65 except that instead of using state information maintained
66 in a global variable,
67 it uses the state information in the argument pointed to by
68 .IR buf .
69 The generated random number is returned in the argument
70 .IR result .
71
72 The
73 .BR srandom_r ()
74 function is like
75 .BR srandom (3),
76 except that it initializes the seed for the random number generator
77 whose state is maintained in the object pointed to by
78 .IR buf ,
79 instead of the seed associated with the global state variable.
80
81 The
82 .BR initstate_r ()
83 function is like
84 .BR initstate (3)
85 except that it initializes the state in the object pointed to by
86 .IR buf ,
87 rather than initializing the global state variable.
88
89 The
90 .BR setstate_r ()
91 function is like
92 .BR setstate (3)
93 except that it modifies the state in the object pointer to by
94 .IR buf ,
95 rather than modifying the global state variable.
96 .SH "RETURN VALUE"
97 All of these functions return 0 on success, or \-1 on error.
98 .SH ERRORS
99 .TP
100 .B EINVAL
101 A state array of less than 8 bytes was specified to
102 .BR initstate_r ().
103 .TP
104 .B EINVAL
105 The
106 .I statebuf
107 or
108 .I buf
109 argument to
110 .BR setstate_r ()
111 was NULL.
112 .TP
113 .B EINVAL
114 The
115 .I buf
116 or
117 .I result
118 argument to
119 .BR random_r ()
120 was NULL.
121 .SH "CONFORMING 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.
125 .SH "SEE ALSO"
126 .BR drand48 (3),
127 .BR rand (3),
128 .BR random (3)