drand48のヘルプ・マニュアル
日本語 英語
drand48 --help
man drand48
DRAND48(3) Linux Programmer’s Manual DRAND48(3)
名前
drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48,
lcong48 - 一様分布する疑似乱数を生成する関数
書式
#include
double drand48(void);
double erand48(unsigned short xsubi[3]);
long int lrand48(void);
long int nrand48(unsigned short xsubi[3]);
long int mrand48(void);
long int jrand48(unsigned short xsubi[3]);
void srand48(long int seedval);
unsigned short *seed48(unsigned short seed16v[3]);
void lcong48(unsigned short param[7]);
glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):
上記の全ての関数: _SVID_SOURCE || _XOPEN_SOURCE
説明
これらの関数は線形合同アルゴリズムと 48ビット整数演算を用いて疑似乱数を
生成する。
関 数 drand48() と erand48() は、区間 [0.0, 1.0) で一様分布する非負の倍
精度浮動小数点実数値を返す。
関数 lrand48() と nrand48() は 0 と 2^31 の間で一様分布する非負のロング
整数を返す。
関数 mrand48() と jrand48() は -2^31 と 2^31 の間で一様分布する符号付き
ロング整数を返す。
関数 srand48(), seed48(), lcong48() は初期化関数である。関数 drand48(),
lrand48(), mrand48() を使用する前に、これらの初期化関数のいずれかを呼ぶ
べきである。関数 erand48(), nrand48(), jrand48() は初めに初期化関数を呼
ぶことを必要としない。
ここで説明しているすべての関数は 48ビットの整数のシーケンス (Xi) を生成
することで機能している。生成方法は以下の線形合同の式による。
Xn+1 = (aXn + c) mod m,
ここで n >= 0 である。パラメータが m = 2^48 であるため、48ビット整数 演
算 が行われている。 lcong48() が呼ばれていない場合、a と c は以下の式で
与えられる。
a = 0x5DEECE66D
c = 0xB
関数 drand48(), erand48(), lrand48(), nrand48(), mrand48(), jrand48()
で 返される値は次のようにして計算される。はじめに、次の48ビットの Xi が
計算される。そして、返すべきデータの型に依存した適切なビット数が Xi の
上位ビットからコピーされる。最後に、この値を返り値に変換する。
関数 drand48(), lrand48(), mrand48() は最後に生成された48ビットの Xi を
内部バッファに格納する。配列の形の引数 xsubi に個々の Xi の値を格納でき
るような領域を確保することを、関数 erand48(), nrand48(), jrand48() は、
呼び出し側のプログラムに要求する。これらの関数は、はじめてそれらの関 数
を呼ぶ前に Xi の初期値を配列に代入することで初期化される。
初期化関数 srand48() は、Xi の上位32ビットを引数 seedval に設定する。下
位の16ビットは、適当に決められた値である0x330Eに設定される。
初期化関数 seed48() は、Xi の値を、配列の形をした引数である seed16v の
中で指定された 48ビットの値に設定する。 Xi の前の値は内部バッファにコピ
ーされ、このバッファへのポインタが seed48() によって返される。
初期化関数 lcong48() は使用者が Xi, a, c の初期値を指定するための関数で
あ る 。 配 列 の 形 を した引数の要素はそれぞれ、param[0-2] は Xi を、
param[3-5] は a を、param[6] は c を指定するものである。 lcong48() が呼
ばれた後で、 srand48() か seed48() を呼ぶと、前述の a と c の標準値が再
び設定される。
準拠
SVr4, POSIX.1-2001.
注意
SVID 3 ではこれらの関数は時代遅れと宣言されている。 SVID 3 では rand(3)
が代わりに使用されるべきだと記述されている。
関連項目
rand(3), random(3)
2007-07-26 DRAND48(3)
DRAND48(3) Linux Programmer’s Manual DRAND48(3)
NAME
drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48,
lcong48 - generate uniformly distributed pseudo-random numbers
SYNOPSIS
#include
double drand48(void);
double erand48(unsigned short xsubi[3]);
long int lrand48(void);
long int nrand48(unsigned short xsubi[3]);
long int mrand48(void);
long int jrand48(unsigned short xsubi[3]);
void srand48(long int seedval);
unsigned short *seed48(unsigned short seed16v[3]);
void lcong48(unsigned short param[7]);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
All functions shown above: _SVID_SOURCE || _XOPEN_SOURCE
DESCRIPTION
These functions generate pseudo-random numbers using the linear congru-
ential algorithm and 48-bit integer arithmetic.
The drand48() and erand48() functions return non-negative double-preci-
sion floating-point values uniformly distributed between [0.0, 1.0).
The lrand48() and nrand48() functions return non-negative long integers
uniformly distributed between 0 and 2^31.
The mrand48() and jrand48() functions return signed long integers uni-
formly distributed between -2^31 and 2^31.
The srand48(), seed48() and lcong48() functions are initialization
functions, one of which should be called before using drand48(),
lrand48() or mrand48(). The functions erand48(), nrand48() and
jrand48() do not require an initialization function to be called first.
All the functions work by generating a sequence of 48-bit integers, Xi,
according to the linear congruential formula:
Xn+1 = (aXn + c) mod m, where n >= 0
The parameter m = 2^48, hence 48-bit integer arithmetic is performed.
Unless lcong48() is called, a and c are given by:
a = 0x5DEECE66D
c = 0xB
The value returned by any of the functions drand48(), erand48(),
lrand48(), nrand48(), mrand48() or jrand48() is computed by first gen-
erating the next 48-bit Xi in the sequence. Then the appropriate num-
ber of bits, according to the type of data item to be returned, is
copied from the high-order bits of Xi and transformed into the returned
value.
The functions drand48(), lrand48() and mrand48() store the last 48-bit
Xi generated in an internal buffer. The functions erand48(), nrand48()
and jrand48() require the calling program to provide storage for the
successive Xi values in the array argument xsubi. The functions are
initialized by placing the initial value of Xi into the array before
calling the function for the first time.
The initializer function srand48() sets the high order 32-bits of Xi to
the argument seedval. The low order 16-bits are set to the arbitrary
value 0x330E.
The initializer function seed48() sets the value of Xi to the 48-bit
value specified in the array argument seed16v. The previous value of
Xi is copied into an internal buffer and a pointer to this buffer is
returned by seed48().
The initialization function lcong48() allows the user to specify ini-
tial values for Xi, a and c. Array argument elements param[0-2] spec-
ify Xi, param[3-5] specify a, and param[6] specifies c. After
lcong48() has been called, a subsequent call to either srand48() or
seed48() will restore the standard values of a and c.
CONFORMING TO
SVr4, POSIX.1-2001.
NOTES
These functions are declared obsolete by SVID 3, which states that
rand(3) should be used instead.
SEE ALSO
rand(3), random(3)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
2007-07-26 DRAND48(3)