1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
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 .\" References consulted:
24 .\" Linux libc source code
25 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
27 .\" Modified Sat Jul 24 19:46:03 1993 by Rik Faith (faith@cs.unc.edu)
29 .\" Japanese Version Copyright (c) 1997 YOSHINO Takashi
30 .\" all rights reserved.
31 .\" Translated Mon Jan 20 20:04:05 JST 1997
32 .\" by YOSHINO Takashi <yoshino@civil.jcn.nihon-u.ac.jp>
34 .\" WORD: internal buffer ÆâÉô¥Ð¥Ã¥Õ¥¡
36 .TH DRAND48 3 2007-07-26 "" "Linux Programmer's Manual"
39 .\"O drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48,
40 .\"O lcong48 \- generate uniformly distributed pseudo-random numbers
41 drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48,
42 lcong48 \- °ìÍÍʬÉÛ¤¹¤ëµ¿»÷Íð¿ô¤òÀ¸À®¤¹¤ë´Ø¿ô
46 .B #include <stdlib.h>
48 .B double drand48(void);
50 .BI "double erand48(unsigned short " xsubi [3]);
52 .B long int lrand48(void);
54 .BI "long int nrand48(unsigned short " xsubi [3]);
56 .B long int mrand48(void);
58 .BI "long int jrand48(unsigned short " xsubi [3]);
60 .BI "void srand48(long int " seedval );
62 .BI "unsigned short *seed48(unsigned short " seed16v [3]);
64 .BI "void lcong48(unsigned short " param [7]);
68 .\"O Feature Test Macro Requirements for glibc (see
69 .\"O .BR feature_test_macros (7)):
70 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
71 .RB ( feature_test_macros (7)
76 .\"O All functions shown above:
87 _SVID_SOURCE || _XOPEN_SOURCE
91 .\"O These functions generate pseudo-random numbers using the linear congruential
92 .\"O algorithm and 48-bit integer arithmetic.
93 ¤³¤ì¤é¤Î´Ø¿ô¤ÏÀþ·Á¹çƱ¥¢¥ë¥´¥ê¥º¥à¤È 48¥Ó¥Ã¥ÈÀ°¿ô±é»»¤òÍѤ¤¤Æ
100 .\"O functions return nonnegative
101 .\"O double-precision floating-point values uniformly distributed between
107 ¤Ï¡¢¶è´Ö [0.0, 1.0) ¤Ç
108 °ìÍÍʬÉÛ¤¹¤ëÈóÉé¤ÎÇÜÀºÅÙÉâÆ°¾®¿ôÅÀ¼Â¿ôÃͤòÊÖ¤¹¡£
114 .\"O functions return nonnegative
115 .\"O long integers uniformly distributed between 0 and 2^31.
120 ¤Ï 0 ¤È 2^31 ¤Î´Ö¤Ç°ìÍÍʬÉÛ¤¹¤ë
121 ÈóÉé¤Î¥í¥ó¥°À°¿ô¤òÊÖ¤¹¡£
127 .\"O functions return signed long
128 .\"O integers uniformly distributed between \-2^31 and 2^31.
134 \-2^31 ¤È 2^31 ¤Î´Ö¤Ç°ìÍÍʬÉÛ¤¹¤ëÉä¹æÉÕ¤¥í¥ó¥°À°¿ô¤òÊÖ¤¹¡£
142 .\"O initialization functions, one of which should be called before using
153 .\"O an initialization function to be called first.
165 »ÈÍѤ¹¤ëÁ°¤Ë¡¢¤³¤ì¤é¤Î½é´ü²½´Ø¿ô¤Î¤¤¤º¤ì¤«¤ò¸Æ¤Ö¤Ù¤¤Ç¤¢¤ë¡£
171 ½é´ü²½´Ø¿ô¤ò¸Æ¤Ö¤³¤È¤òɬÍפȤ·¤Ê¤¤¡£
173 .\"O All the functions work by generating a sequence of 48-bit integers,
174 .\"O \fIXi\fP, according to the linear congruential formula:
175 ¤³¤³¤ÇÀâÌÀ¤·¤Æ¤¤¤ë¤¹¤Ù¤Æ¤Î´Ø¿ô¤Ï 48¥Ó¥Ã¥È¤ÎÀ°¿ô¤Î
176 ¥·¡¼¥±¥ó¥¹ (\fIXi\fP) ¤òÀ¸À®¤¹¤ë¤³¤È¤Ç
177 µ¡Ç½¤·¤Æ¤¤¤ë¡£À¸À®ÊýË¡¤Ï°Ê²¼¤ÎÀþ·Á¹çƱ¤Î¼°¤Ë¤è¤ë¡£
181 .B Xn+1 = (aXn + c) mod m,
185 .\"O The parameter \fIm\fP = 2^48, hence 48-bit integer arithmetic is performed.
188 .\"O is called, \fIa\fP and \fIc\fP are given by:
189 ¤³¤³¤Ç n >= 0 ¤Ç¤¢¤ë¡£
190 ¥Ñ¥é¥á¡¼¥¿¤¬ \fIm\fP = 2^48 ¤Ç¤¢¤ë¤¿¤á¡¢48¥Ó¥Ã¥ÈÀ°¿ô±é»»¤¬¹Ô¤ï¤ì¤Æ¤¤¤ë¡£
192 ¤¬¸Æ¤Ð¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¡¢\fIa\fP ¤È \fIc\fP ¤Ï°Ê²¼¤Î¼°¤ÇÍ¿¤¨¤é¤ì¤ë¡£
201 .\"O The value returned by any of the functions
210 .\"O computed by first generating the next 48-bit \fIXi\fP in the sequence.
211 .\"O Then the appropriate number of bits, according to the type of data item to
212 .\"O be returned, is copied from the high-order bits of \fIXi\fP and transformed
213 .\"O into the returned value.
221 ¤ÇÊÖ¤µ¤ì¤ëÃͤϼ¡¤Î¤è¤¦¤Ë¤·¤Æ·×»»¤µ¤ì¤ë¡£
222 ¤Ï¤¸¤á¤Ë¡¢¼¡¤Î48¥Ó¥Ã¥È¤Î \fIXi\fP ¤¬·×»»¤µ¤ì¤ë¡£
223 ¤½¤·¤Æ¡¢ÊÖ¤¹¤Ù¤¥Ç¡¼¥¿¤Î·¿¤Ë°Í¸¤·¤¿Å¬ÀÚ¤Ê
224 ¥Ó¥Ã¥È¿ô¤¬ \fIXi\fP ¤Î¾å°Ì¥Ó¥Ã¥È¤«¤é¥³¥Ô¡¼¤µ¤ì¤ë¡£
225 ºÇ¸å¤Ë¡¢¤³¤ÎÃͤòÊÖ¤êÃͤËÊÑ´¹¤¹¤ë¡£
233 .\"O the last 48-bit \fIXi\fP generated in an internal buffer.
239 .\"O require the calling
240 .\"O program to provide storage for the successive \fIXi\fP values in the array
241 .\"O argument \fIxsubi\fP.
242 .\"O The functions are initialized by placing the initial
243 .\"O value of \fIXi\fP into the array before calling the function for the first
250 ºÇ¸å¤ËÀ¸À®¤µ¤ì¤¿48¥Ó¥Ã¥È¤Î \fIXi\fP ¤òÆâÉô¥Ð¥Ã¥Õ¥¡¤Ë³ÊǼ¤¹¤ë¡£
251 ÇÛÎó¤Î·Á¤Î°ú¿ô \fIxsubi\fP ¤Ë¸Ä¡¹¤Î \fIXi\fP ¤ÎÃͤò
252 ³ÊǼ¤Ç¤¤ë¤è¤¦¤ÊÎΰè¤ò³ÎÊݤ¹¤ë¤³¤È¤ò¡¢
258 ¸Æ¤Ó½Ð¤·Â¦¤Î¥×¥í¥°¥é¥à¤ËÍ׵᤹¤ë¡£
259 ¤³¤ì¤é¤Î´Ø¿ô¤Ï¡¢¤Ï¤¸¤á¤Æ¤½¤ì¤é¤Î´Ø¿ô¤ò¸Æ¤ÖÁ°¤Ë \fIXi\fP ¤Î½é´üÃͤòÇÛÎó¤Ë
260 ÂåÆþ¤¹¤ë¤³¤È¤Ç½é´ü²½¤µ¤ì¤ë¡£
262 .\"O The initializer function
264 .\"O sets the high order 32-bits of
265 .\"O \fIXi\fP to the argument \fIseedval\fP.
266 .\"O The low order 16-bits are set
267 .\"O to the arbitrary value 0x330E.
271 ¾å°Ì32¥Ó¥Ã¥È¤ò°ú¿ô \fIseedval\fP ¤ËÀßÄꤹ¤ë¡£
272 ²¼°Ì¤Î16¥Ó¥Ã¥È¤Ï¡¢Å¬Åö¤Ë·è¤á¤é¤ì¤¿ÃͤǤ¢¤ë0x330E¤ËÀßÄꤵ¤ì¤ë¡£
274 .\"O The initializer function
276 .\"O sets the value of \fIXi\fP to
277 .\"O the 48-bit value specified in the array argument \fIseed16v\fP.
279 .\"O previous value of \fIXi\fP is copied into an internal buffer and a
280 .\"O pointer to this buffer is returned by
284 ¤Ï¡¢\fIXi\fP ¤ÎÃͤò¡¢
285 ÇÛÎó¤Î·Á¤ò¤·¤¿°ú¿ô¤Ç¤¢¤ë \fIseed16v\fP ¤ÎÃæ¤Ç»ØÄꤵ¤ì¤¿ 48¥Ó¥Ã¥È¤ÎÃͤËÀßÄꤹ¤ë¡£
286 \fIXi\fP ¤ÎÁ°¤ÎÃͤÏÆâÉô¥Ð¥Ã¥Õ¥¡¤Ë¥³¥Ô¡¼¤µ¤ì¡¢¤³¤Î¥Ð¥Ã¥Õ¥¡¤Ø¤Î¥Ý¥¤¥ó¥¿¤¬
290 .\"O The initialization function
292 .\"O allows the user to specify
293 .\"O initial values for \fIXi\fP, \fIa\fP and \fIc\fP.
295 .\"O elements \fIparam[0-2]\fP specify \fIXi\fP, \fIparam[3-5]\fP specify
296 .\"O \fIa\fP, and \fIparam[6]\fP specifies \fIc\fP.
299 .\"O has been called, a subsequent call to either
303 .\"O will restore the standard values of \fIa\fP and \fIc\fP.
306 ¤Ï»ÈÍѼԤ¬ \fIXi\fP, \fIa\fP, \fIc\fP ¤Î
307 ½é´üÃͤò»ØÄꤹ¤ë¤¿¤á¤Î´Ø¿ô¤Ç¤¢¤ë¡£
308 ÇÛÎó¤Î·Á¤ò¤·¤¿°ú¿ô¤ÎÍ×ÁǤϤ½¤ì¤¾¤ì¡¢\fIparam[0-2]\fP ¤Ï \fIXi\fP ¤ò¡¢
309 \fIparam[3-5]\fP ¤Ï \fIa\fP ¤ò¡¢\fIparam[6]\fP ¤Ï \fIc\fP ¤ò»ØÄꤹ¤ë¤â¤Î
316 ¤ò¸Æ¤Ö¤È¡¢Á°½Ò¤Î \fIa\fP ¤È \fIc\fP ¤Î
317 ɸ½àÃͤ¬ºÆ¤ÓÀßÄꤵ¤ì¤ë¡£
322 .\"O These functions are declared obsolete by SVID 3, which states that
324 .\"O should be used instead.
325 SVID 3 ¤Ç¤Ï¤³¤ì¤é¤Î´Ø¿ô¤Ï»þÂåÃÙ¤ì¤ÈÀë¸À¤µ¤ì¤Æ¤¤¤ë¡£
328 ¤¬Âå¤ï¤ê¤Ë»ÈÍѤµ¤ì¤ë¤Ù¤¤À¤Èµ½Ò¤µ¤ì¤Æ¤¤¤ë¡£