OSDN Git Service

(split) Convert release and draft pages to UTF-8.
[linuxjm/LDP_man-pages.git] / release / man3 / drand48.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 Sat Jul 24 19:46:03 1993 by Rik Faith (faith@cs.unc.edu)
28 .\"
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>
33 .\"
34 .\" WORD: internal buffer  内部バッファ
35 .\"
36 .TH DRAND48 3  2007-07-26 "" "Linux Programmer's Manual"
37 .SH 名前
38 drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48,
39 lcong48 \- 一様分布する疑似乱数を生成する関数
40 .SH 書式
41 .nf
42 .B #include <stdlib.h>
43 .sp
44 .B double drand48(void);
45 .sp
46 .BI "double erand48(unsigned short " xsubi [3]);
47 .sp
48 .B long int lrand48(void);
49 .sp
50 .BI "long int nrand48(unsigned short " xsubi [3]);
51 .sp
52 .B long int mrand48(void);
53 .sp
54 .BI "long int jrand48(unsigned short " xsubi [3]);
55 .sp
56 .BI "void srand48(long int " seedval );
57 .sp
58 .BI "unsigned short *seed48(unsigned short " seed16v [3]);
59 .sp
60 .BI "void lcong48(unsigned short " param [7]);
61 .fi
62 .sp
63 .in -4n
64 glibc 向けの機能検査マクロの要件
65 .RB ( feature_test_macros (7)
66 参照):
67 .in
68 .sp
69 .ad l
70 上記の全ての関数:
71 .\" .BR drand48 (),
72 .\" .BR erand48 (),
73 .\" .BR lrand48 (),
74 .\" .BR nrand48 (),
75 .\" .BR mrand48 (),
76 .\" .BR jrand48 (),
77 .\" .BR srand48 (),
78 .\" .BR seed48 (),
79 .\" .BR lcong48 ():
80 _SVID_SOURCE || _XOPEN_SOURCE
81 .ad b
82 .SH 説明
83 これらの関数は線形合同アルゴリズムと 48ビット整数演算を用いて
84 疑似乱数を生成する。
85 .PP
86 関数
87 .BR drand48 ()
88
89 .BR erand48 ()
90 は、区間 [0.0, 1.0) で
91 一様分布する非負の倍精度浮動小数点実数値を返す。
92 .PP
93 関数
94 .BR lrand48 ()
95
96 .BR nrand48 ()
97 は 0 と 2^31 の間で一様分布する
98 非負のロング整数を返す。
99 .PP
100 関数
101 .BR mrand48 ()
102
103 .BR jrand48 ()
104
105 \-2^31 と 2^31 の間で一様分布する符号付きロング整数を返す。
106 .PP
107 関数
108 .BR srand48 (),
109 .BR seed48 (),
110 .BR lcong48 ()
111 は初期化関数
112 である。
113 関数
114 .BR drand48 (),
115 .BR lrand48 (),
116 .BR mrand48 ()
117
118 使用する前に、これらの初期化関数のいずれかを呼ぶべきである。
119 関数
120 .BR erand48 (),
121 .BR nrand48 (),
122 .BR jrand48 ()
123 は初めに
124 初期化関数を呼ぶことを必要としない。
125 .PP
126 ここで説明しているすべての関数は 48ビットの整数の
127 シーケンス (\fIXi\fP) を生成することで
128 機能している。生成方法は以下の線形合同の式による。
129 .sp
130 .nf
131 .RS
132 .B Xn+1 = (aXn + c) mod m,
133 .RE
134 .fi
135 .sp
136 ここで n >= 0 である。
137 パラメータが \fIm\fP = 2^48 であるため、48ビット整数演算が行われている。
138 .BR lcong48 ()
139 が呼ばれていない場合、\fIa\fP と \fIc\fP は以下の式で与えられる。
140 .sp
141 .nf
142 .RS
143 .B a = 0x5DEECE66D
144 .B c = 0xB
145 .RE
146 .fi
147 .sp
148 関数
149 .BR drand48 (),
150 .BR erand48 (),
151 .BR lrand48 (),
152 .BR nrand48 (),
153 .BR mrand48 (),
154 .BR jrand48 ()
155 で返される値は次のようにして計算される。
156 はじめに、次の48ビットの \fIXi\fP が計算される。
157 そして、返すべきデータの型に依存した適切な
158 ビット数が \fIXi\fP の上位ビットからコピーされる。
159 最後に、この値を返り値に変換する。
160 .PP
161 関数
162 .BR drand48 (),
163 .BR lrand48 (),
164 .BR mrand48 ()
165
166 最後に生成された48ビットの \fIXi\fP を内部バッファに格納する。
167 配列の形の引数 \fIxsubi\fP に個々の \fIXi\fP の値を
168 格納できるような領域を確保することを、
169 関数
170 .BR erand48 (),
171 .BR nrand48 (),
172 .BR jrand48 ()
173 は、
174 呼び出し側のプログラムに要求する。
175 これらの関数は、はじめてそれらの関数を呼ぶ前に \fIXi\fP の初期値を配列に
176 代入することで初期化される。
177 .PP
178 初期化関数
179 .BR srand48 ()
180 は、\fIXi\fP の
181 上位32ビットを引数 \fIseedval\fP に設定する。
182 下位の16ビットは、適当に決められた値である0x330Eに設定される。
183 .PP
184 初期化関数
185 .BR seed48 ()
186 は、\fIXi\fP の値を、
187 配列の形をした引数である \fIseed16v\fP の中で指定された 48ビットの値に設定する。
188 \fIXi\fP の前の値は内部バッファにコピーされ、このバッファへのポインタが
189 .BR seed48 ()
190 によって返される。
191 .PP
192 初期化関数
193 .BR lcong48 ()
194 は使用者が \fIXi\fP, \fIa\fP, \fIc\fP の
195 初期値を指定するための関数である。
196 配列の形をした引数の要素はそれぞれ、\fIparam[0-2]\fP は \fIXi\fP を、
197 \fIparam[3-5]\fP は \fIa\fP を、\fIparam[6]\fP は \fIc\fP を指定するもの
198 である。
199 .BR lcong48 ()
200 が呼ばれた後で、
201 .BR srand48 ()
202
203 .BR seed48 ()
204 を呼ぶと、前述の \fIa\fP と \fIc\fP の
205 標準値が再び設定される。
206 .SH 準拠
207 SVr4, POSIX.1-2001.
208 .SH 注意
209 SVID 3 ではこれらの関数は時代遅れと宣言されている。
210 SVID 3 では
211 .BR rand (3)
212 が代わりに使用されるべきだと記述されている。
213 .SH 関連項目
214 .BR rand (3),
215 .BR random (3)