.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\" References consulted: .\" Linux libc source code .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) .\" 386BSD man pages .\" Modified Sat Jul 24 19:46:03 1993 by Rik Faith (faith@cs.unc.edu) .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 1997 YOSHINO Takashi .\" all rights reserved. .\" Translated Mon Jan 20 20:04:05 JST 1997 .\" by YOSHINO Takashi .\" .TH DRAND48 3 2020\-11\-01 "" "Linux Programmer's Manual" .SH 名前 drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48, lcong48 \- 一様分布する疑似乱数を生成する関数 .SH 書式 .nf \fB#include \fP .PP \fBdouble drand48(void);\fP .PP \fBdouble erand48(unsigned short \fP\fIxsubi\fP\fB[3]);\fP .PP \fBlong lrand48(void);\fP .PP \fBlong nrand48(unsigned short \fP\fIxsubi\fP\fB[3]);\fP .PP \fBlong mrand48(void);\fP .PP \fBlong jrand48(unsigned short \fP\fIxsubi\fP\fB[3]);\fP .PP \fBvoid srand48(long \fP\fIseedval\fP\fB);\fP .PP \fBunsigned short *seed48(unsigned short \fP\fIseed16v\fP\fB[3]);\fP .PP \fBvoid lcong48(unsigned short \fP\fIparam\fP\fB[7]);\fP .fi .PP .RS -4 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .RE .PP .ad l .\" .BR drand48 (), .\" .BR erand48 (), .\" .BR lrand48 (), .\" .BR nrand48 (), .\" .BR mrand48 (), .\" .BR jrand48 (), .\" .BR srand48 (), .\" .BR seed48 (), .\" .BR lcong48 (): All functions shown above: _XOPEN_SOURCE || /* Glibc since 2.19: */ _DEFAULT_SOURCE || /* Glibc versions <= 2.19: */ _SVID_SOURCE .ad b .SH 説明 これらの関数は線形合同アルゴリズムと 48ビット整数演算を用いて 疑似乱数を生成する。 .PP 関数 \fBdrand48\fP() と \fBerand48\fP() は、区間 [0.0,\ 1.0) で 一様分布する非負の倍精度浮動小数点実数値を返す。 .PP 関数 \fBlrand48\fP() と \fBnrand48\fP() は、区間 [0,\ 2^31) で一様分布する非負のロング整数を返す。 .PP 関数 \fBmrand48\fP() と \fBjrand48\fP() は、区間 [\-2^31,\ 2^31) で一様分布する符号付きロング整数を返す。 .PP 関数 \fBsrand48\fP(), \fBseed48\fP(), \fBlcong48\fP() は初期化関数 である。 関数 \fBdrand48\fP(), \fBlrand48\fP(), \fBmrand48\fP() を 使用する前に、これらの初期化関数のいずれかを呼ぶべきである。 関数 \fBerand48\fP(), \fBnrand48\fP(), \fBjrand48\fP() は初めに 初期化関数を呼ぶことを必要としない。 .PP ここで説明しているすべての関数は 48ビットの整数の シーケンス (\fIXi\fP) を生成することで 機能している。生成方法は以下の線形合同の式による。 .PP .in +4n .EX \fBXn+1 = (aXn + c) mod m,\fP .EE .in .PP ここで n >= 0 である。 パラメーターが \fIm\fP = 2^48 であるため、48ビット整数演算が行われている。 \fBlcong48\fP() が呼ばれていない場合、\fIa\fP と \fIc\fP は以下の式で与えられる。 .PP .in +4n .EX \fBa = 0x5DEECE66D\fP \fBc = 0xB\fP .EE .in .PP 関数 \fBdrand48\fP(), \fBerand48\fP(), \fBlrand48\fP(), \fBnrand48\fP(), \fBmrand48\fP(), \fBjrand48\fP() で返される値は次のようにして計算される。 はじめに、次の48ビットの \fIXi\fP が計算される。 そして、返すべきデータの型に依存した適切な ビット数が \fIXi\fP の上位ビットからコピーされる。 最後に、この値を返り値に変換する。 .PP 関数 \fBdrand48\fP(), \fBlrand48\fP(), \fBmrand48\fP() は 最後に生成された48ビットの \fIXi\fP を内部バッファーに格納する。 配列の形の引数 \fIxsubi\fP に個々の \fIXi\fP の値を 格納できるような領域を確保することを、 関数 \fBerand48\fP(), \fBnrand48\fP(), \fBjrand48\fP() は、 呼び出し側のプログラムに要求する。 これらの関数は、はじめてそれらの関数を呼ぶ前に \fIXi\fP の初期値を配列に 代入することで初期化される。 .PP 初期化関数 \fBsrand48\fP() は、\fIXi\fP の 上位32ビットを引数 \fIseedval\fP に設定する。 下位の16ビットは、適当に決められた値である0x330Eに設定される。 .PP 初期化関数 \fBseed48\fP() は、\fIXi\fP の値を、 配列の形をした引数である \fIseed16v\fP の中で指定された 48ビットの値に設定する。 \fIXi\fP の前の値は内部バッファーにコピーされ、このバッファーへのポインターが \fBseed48\fP() によって返される。 .PP 初期化関数 \fBlcong48\fP() は使用者が \fIXi\fP, \fIa\fP, \fIc\fP の 初期値を指定するための関数である。 配列の形をした引数の要素はそれぞれ、\fIparam[0\-2]\fP は \fIXi\fP を、 \fIparam[3\-5]\fP は \fIa\fP を、\fIparam[6]\fP は \fIc\fP を指定するもの である。 \fBlcong48\fP() が呼ばれた後で、 \fBsrand48\fP() か \fBseed48\fP() を呼ぶと、前述の \fIa\fP と \fIc\fP の 標準値が再び設定される。 .SH 属性 この節で使用されている用語の説明については、 \fBattributes\fP(7) を参照。 .ad l .TS allbox; lb lb lb lw21 l lw22. インターフェース 属性 値 T{ \fBdrand48\fP(), \fBerand48\fP(), \fBlrand48\fP(), \fBnrand48\fP(), \fBmrand48\fP(), \fBjrand48\fP(), \fBsrand48\fP(), \fBseed48\fP(), \fBlcong48\fP() T} Thread safety T{ MT\-Unsafe race:drand48 T} .TE .ad .PP 上記の関数は、 乱数生成に使用する状態情報をグローバルに保持する。 そのため、 これらの関数はスレッドセーフではない。 .SH 準拠 POSIX.1\-2001, POSIX.1\-2008, SVr4. .SH 関連項目 \fBrand\fP(3), \fBrandom\fP(3) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は \%https://www.kernel.org/doc/man\-pages/ に書かれている。