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 Sun Mar 28 00:25:51 1993, David Metcalfe
28 .\" Modified Sat Jul 24 18:13:39 1993 by Rik Faith (faith@cs.unc.edu)
29 .\" Modified Sun Aug 20 21:47:07 2000, aeb
31 .\" Japanese Version Copyright (c) 1997 YOSHINO Takashi
32 .\" all rights reserved.
33 .\" Translated 1997-01-21, YOSHINO Takashi <yoshino@civil.jcn.nihon-u.ac.jp>
34 .\" Updated 2008-08-08, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
36 .\" WORD: nonlinear additive feedback 非線形加法フィードバック
37 .\" WORD: state array 状態配列
39 .TH RANDOM 3 2010-09-20 "GNU" "Linux Programmer's Manual"
41 random, srandom, initstate, setstate \- 乱数を生成する関数
44 .B #include <stdlib.h>
46 .B long int random(void);
48 .BI "void srandom(unsigned int " seed );
50 .BI "char *initstate(unsigned int " seed ", char *" state ", size_t " n );
52 .BI "char *setstate(char *" state );
57 .RB ( feature_test_macros (7)
67 _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
68 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
73 関数は、非線形加法フィードバックを用いた乱数生成関数である。
74 この関数は、0 から \fBRAND_MAX\fR までの疑似乱数を返す。
75 そのために 31 個のロング整数からなるデフォルトの表を使用する。
76 この乱数を生成する関数の周期はとても長く、およそ
77 .I "16\ *\ ((2^31)\ \-\ 1)"
102 では、状態配列の大きさ \fIn\fP は
103 使用する関数の乱数生成の性能の程度を決定するために使用される
104 \(em 状態配列が大きい程、乱数の性能はよくなる。
105 \fIseed\fP は初期化のための種である。
106 これは乱数系列の開始位置を決定するものであり、
107 この値を指定することで同一の開始位置から乱数の生成を
119 次に呼び出されるまで、乱数の生成に使用される。
142 で8バイトよりも小さい状態配列を指定した。
144 4.3BSD, POSIX.1-2001.
146 状態配列 \fIn\fP の大きさの現在の「最適」値は
147 8、32、64、128、256 バイトである。
148 その他の量を指定した場合には、指定した量を越えない上述の値に
150 8 バイト未満の量を指定した場合にはエラーの原因となる。
154 を使うような状況では、この関数を使用すべきではない。
160 .I Numerical Recipes in C: The Art of Scientific Computing
161 (William H. Press, Brian P. Flannery, Saul A. Teukolsky, William
162 T. Vetterling; New York: Cambridge University Press, 2007, 3rd ed.)
163 では実用的な乱数生成を論点とした優れた議論が第 7 章 (乱数) で展開されている。
165 より理論的な議論については Donald E. Knuth の
166 .IR "The Art of Computer Programming" ,
167 volume 2 (Seminumerical Algorithms), 2nd ed.; Reading, Massachusetts:
168 Addison-Wesley Publishing Company, 1981
169 の第 3 章 (乱数) を見よ。ここでは、
170 たくさんの実用的な話題についても深く網羅されている。