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.
23 .\" Japanese Version Copyright (c) 2008 Akihiro MOTOKI
24 .\" all rights reserved.
25 .\" Translated 2008-08-21, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.04
28 .TH RANDOM_R 3 2008-03-07 "GNU" "Linux Programmer's Manual"
31 .\"O random_r, srandom_r, initstate_r, setstate_r \- reentrant
32 .\"O random number generator
33 random_r, srandom_r, initstate_r, setstate_r \- ¥ê¥¨¥ó¥È¥é¥ó¥È¤Ê
38 .B #include <stdlib.h>
40 .BI "int random_r(struct random_data *" buf ", int32_t *" result );
42 .BI "int srandom_r(unsigned int " seed ", struct random_data *" buf );
44 .BI "int initstate_r(unsigned int " seed ", char *" statebuf ,
45 .BI " size_t " statelen ", struct random_data *" buf );
47 .BI "int setstate_r(char *" statebuf ", struct random_data *" buf );
51 .\"O Feature Test Macro Requirements for glibc (see
52 .\"O .BR feature_test_macros (7)):
53 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
54 .RB ( feature_test_macros (7)
64 _SVID_SOURCE || _BSD_SOURCE
69 .\"O These functions are the reentrant equivalents
70 .\"O of the functions described in
72 .\"O They are suitable for use in multithreaded programs where each thread
73 .\"O needs to obtain an independent, reproducible sequence of random numbers.
76 ¤ÇÀâÌÀ¤µ¤ì¤Æ¤¤¤ë´Ø¿ô¤Î¥ê¥¨¥ó¥È¥é¥ó¥ÈÈǤǡ¢Åù²Á¤Êµ¡Ç½¤ò»ý¤Ä¡£
77 ¤³¤ì¤é¤Ï¡¢ÆÈΩ¤·¤¿ºÆ¸½²Äǽ¤ÊÍð¿ôÎó¤ò³Æ¥¹¥ì¥Ã¥É¤¬ÆÀ¤ëɬÍפ¬¤¢¤ë¤è¤¦¤Ê
78 ¥Þ¥ë¥Á¥¹¥ì¥Ã¥É¡¦¥×¥í¥°¥é¥à¤Ç¤Î»ÈÍѤËŬ¤·¤Æ¤¤¤ë¡£
84 .\"O except that instead of using state information maintained
85 .\"O in a global variable,
86 .\"O it uses the state information in the argument pointed to by
88 .\"O The generated random number is returned in the argument
94 Âç°èÊÑ¿ô (global variable) ¤Ç´ÉÍý¤µ¤ì¤ë¾õÂÖ¾ðÊó¤ò»È¤¦¤Î¤Ç¤Ï¤Ê¤¯¡¢
96 ¤¬»Ø¤¹°ú¤¿ô¤Ë³ÊǼ¤µ¤ì¤¿¾õÂÖ¾ðÊó¤ò»È¤¦¡£
97 À¸À®¤µ¤ì¤¿Íð¿ô¤Ï°ú¤¿ô
99 ¤Ë³ÊǼ¤µ¤ì¤ÆÊÖ¤µ¤ì¤ë¡£
102 .\"O .BR srandom_r ()
103 .\"O function is like
104 .\"O .BR srandom (3),
105 .\"O except that it initializes the seed for the random number generator
106 .\"O whose state is maintained in the object pointed to by
108 .\"O instead of the seed associated with the global state variable.
113 Âç°èÊÑ¿ô¤Ç´ÉÍý¤µ¤ì¤ë¾õÂÖ¤ËÂбþ¤¹¤ëÍð¿ôÀ¸À®´ï¤Î¼ï¤Ç¤Ï¤Ê¤¯¡¢
115 ¤¬»Ø¤¹¥ª¥Ö¥¸¥§¥¯¥È¤Ç´ÉÍý¤µ¤ì¤ë¾õÂÖ¤ËÂбþ¤¹¤ëÍð¿ôÀ¸À®´ï¤Î¼ï¤ò
119 .\"O .BR initstate_r ()
120 .\"O function is like
121 .\"O .BR initstate (3)
122 .\"O except that it initializes the state in the object pointed to by
124 .\"O rather than initializing the global state variable.
128 ¤ÈƱÍͤÀ¤¬¡¢Âç°èÊÑ¿ô¤Ç´ÉÍý¤µ¤ì¤ë¾õÂÖ¤ò½é´ü²½¤¹¤ë¤Î¤Ç¤Ï¤Ê¤¯¡¢
130 ¤¬»Ø¤¹¥ª¥Ö¥¸¥§¥¯¥ÈÆâ¤Î¾õÂÖ¤ò½é´ü²½¤¹¤ë¡£
133 .\"O .BR setstate_r ()
134 .\"O function is like
135 .\"O .BR setstate (3)
136 .\"O except that it modifies the state in the object pointer to by
138 .\"O rather than modifying the global state variable.
142 ¤ÈƱÍͤÀ¤¬¡¢Âç°èÊÑ¿ô¤Ç´ÉÍý¤µ¤ì¤ë¾õÂÖ¤òÊѹ¹¤¹¤ë¤Î¤Ç¤Ï¤Ê¤¯¡¢
144 ¤¬»Ø¤¹¥ª¥Ö¥¸¥§¥¯¥ÈÆâ¤Î¾õÂÖ¤òÊѹ¹¤¹¤ë¡£
145 .\"O .SH "RETURN VALUE"
147 .\"O All of these functions return 0 on success, or \-1 on error.
148 ¤³¤ì¤é¤Î´Ø¿ô¤Ï¡¢À®¸ù¤¹¤ë¤È 0 ¤òÊÖ¤·¡¢
149 ¥¨¥é¡¼¤Î¾ì¹ç¤Ï \-1 ¤òÊÖ¤¹¡£
154 .\"O A state array of less than 8 bytes was specified to
155 .\"O .BR initstate_r ().
156 8 ¥Ð¥¤¥È¤è¤ê¾®¤µ¤¤¾õÂÖÇÛÎó¤¬
166 .\"O .BR setstate_r ()
189 .\"O .SH "CONFORMING TO"
191 .\"O These functions are nonstandard glibc extensions.
192 ¤³¤ì¤é¤Î´Ø¿ô¤ÏÈóɸ½à¤Ç glibc ¤Ë¤è¤ë³ÈÄ¥¤Ç¤¢¤ë¡£
193 .\" These functions appear to be on Tru64, but don't seem to be on
194 .\" Solaris, HP-UX, or FreeBSD.