OSDN Git Service

(split) LDP: Release pages for LDP v3.39.
[linuxjm/LDP_man-pages.git] / release / man3 / random.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
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 .\" References consulted:
24 .\"     Linux libc source code
25 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
26 .\"     386BSD man pages
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
30 .\"
31 .\"*******************************************************************
32 .\"
33 .\" This file was generated with po4a. Translate the source file.
34 .\"
35 .\"*******************************************************************
36 .TH RANDOM 3 2010\-09\-20 GNU "Linux Programmer's Manual"
37 .SH 名前
38 random, srandom, initstate, setstate \- 乱数を生成する関数
39 .SH 書式
40 .nf
41 \fB#include <stdlib.h>\fP
42 .sp
43 \fBlong int random(void);\fP
44
45 \fBvoid srandom(unsigned int \fP\fIseed\fP\fB);\fP
46
47 \fBchar *initstate(unsigned int \fP\fIseed\fP\fB, char *\fP\fIstate\fP\fB, size_t \fP\fIn\fP\fB);\fP
48 .br
49 \fBchar *setstate(char *\fP\fIstate\fP\fB);\fP
50 .fi
51 .sp
52 .in -4n
53 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
54 .in
55 .sp
56 .ad l
57 \fBrandom\fP(), \fBsrandom\fP(), \fBinitstate\fP(), \fBsetstate\fP():
58 .RS 4
59 _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
60 .RE
61 .ad
62 .SH 説明
63 \fBrandom\fP()  関数は、非線形加法フィードバックを用いた乱数生成関数である。 この関数は、0 から \fBRAND_MAX\fP
64 までの疑似乱数を返す。 そのために 31 個のロング整数からなるデフォルトの表を使用する。 この乱数を生成する関数の周期はとても長く、およそ \fI16\ *\ ((2^31)\ \-\ 1)\fP である。
65 .PP
66 \fBsrandom\fP()  関数は、 \fBrandom\fP()  で返される疑似乱数整数系列の種を設定する。 そのためには新しい種を引数にして
67 \fBsrandom\fP()  を呼べばよい。 \fBrandom\fP()  で生成される系列は、 引数に同じ種の値を用いて \fBsrandom\fP()
68 を呼ぶことで再現可能である。 種の値が与えられない場合には \fBrandom\fP()  関数は、自動的に 1 を種に設定する。
69 .PP
70 \fBinitstate\fP()  関数は、 \fBrandom\fP()  で使用される状態配列 \fIstate\fP を初期化する。 \fBinitstate\fP()
71 では、状態配列の大きさ \fIn\fP は 使用する関数の乱数生成の性能の程度を決定するために使用される \(em 状態配列が大きい程、乱数の性能はよくなる。
72 \fIseed\fP は初期化のための種である。 これは乱数系列の開始位置を決定するものであり、 この値を指定することで同一の開始位置から乱数の生成を
73 再開することができる。
74 .PP
75 \fBsetstate\fP()  関数は、 \fBrandom\fP()  で使用される状態配列を変更する。 状態配列 \fIstate\fP は、
76 \fBinitstate\fP()  または \fBsetstate\fP()  が 次に呼び出されるまで、乱数の生成に使用される。 \fIstate\fP は
77 \fBinitstate\fP()  を用いて最初に初期化されているか、 以前に呼び出した \fBsetstate\fP()  の結果でなければならない。
78 .SH 返り値
79 \fBrandom\fP()  関数は 0 と \fBRAND_MAX\fP の間の値を返す。 \fBsrandom\fP()  関数は値を返さない。
80 \fBinitstate\fP()  関数は直前の状態配列へのポインタを返す。 \fBsetstate\fP()  関数は直前の状態配列へのポインタを返し、
81 エラーの場合は NULL を返す。
82 .SH エラー
83 .TP 
84 \fBEINVAL\fP
85 \fBinitstate\fP()  で8バイトよりも小さい状態配列を指定した。
86 .SH 準拠
87 4.3BSD, POSIX.1\-2001.
88 .SH 注意
89 状態配列 \fIn\fP の大きさの現在の「最適」値は 8、32、64、128、256 バイトである。
90 その他の量を指定した場合には、指定した量を越えない上述の値に 最も近い値になる。 8 バイト未満の量を指定した場合にはエラーの原因となる。
91 .PP
92 複数のスレッドが \fBrandom\fP()  を使うような状況では、この関数を使用すべきではない。 その場合には \fBrandom_r\fP(3)
93 を使うこと。
94 .PP
95 乱数の生成は複雑な話題である。 \fINumerical Recipes in C: The Art of Scientific Computing\fP
96 (William H. Press, Brian P. Flannery, Saul A. Teukolsky, William
97 T. Vetterling; New York: Cambridge University Press, 2007, 3rd ed.)
98 では実用的な乱数生成を論点とした優れた議論が第 7 章 (乱数) で展開されている。
99 .PP
100 より理論的な議論については Donald E. Knuth の \fIThe Art of Computer Programming\fP, volume 2
101 (Seminumerical Algorithms), 2nd ed.; Reading, Massachusetts: Addison\-Wesley
102 Publishing Company, 1981 の第 3 章 (乱数) を見よ。ここでは、 たくさんの実用的な話題についても深く網羅されている。
103 .SH 関連項目
104 \fBdrand48\fP(3), \fBrand\fP(3), \fBrandom_r\fP(3), \fBsrand\fP(3)