OSDN Git Service

(split) LDP: Restore and add Copyrights for draft pages
[linuxjm/LDP_man-pages.git] / draft / man3 / random.3
index e22a858..f0190e5 100644 (file)
@@ -1,5 +1,6 @@
 .\" 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.
@@ -19,6 +20,7 @@
 .\"
 .\" 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
 .\" Modified Sat Jul 24 18:13:39 1993 by Rik Faith (faith@cs.unc.edu)
 .\" Modified Sun Aug 20 21:47:07 2000, aeb
 .\"
+.\"*******************************************************************
+.\"
+.\" This file was generated with po4a. Translate the source file.
+.\"
+.\"*******************************************************************
+.\"
 .\" Japanese Version Copyright (c) 1997 YOSHINO Takashi
 .\"       all rights reserved.
 .\" Translated 1997-01-21, YOSHINO Takashi <yoshino@civil.jcn.nihon-u.ac.jp>
 .\" Updated 2008-08-08, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
+.\" Updated 2013-07-24, Akihiro MOTOKI <amotoki@gmail.com>
 .\"
-.\" WORD: nonlinear additive feedback   ÈóÀþ·Á²ÃË¡¥Õ¥£¡¼¥É¥Ð¥Ã¥¯
-.\" WORD: state array   ¾õÂÖÇÛÎó
-.\"
-.TH RANDOM 3  2010-09-20 "GNU" "Linux Programmer's Manual"
-.\"O .SH NAME
-.SH Ì¾Á°
-.\"O random, srandom, initstate, setstate \- random number generator
-random, srandom, initstate, setstate \- Íð¿ô¤òÀ¸À®¤¹¤ë´Ø¿ô
-.\"O .SH SYNOPSIS
-.SH ½ñ¼°
+.TH RANDOM 3 2013\-04\-19 GNU "Linux Programmer's Manual"
+.SH 名前
+random, srandom, initstate, setstate \- 乱数を生成する関数
+.SH 書式
 .nf
-.B #include <stdlib.h>
+\fB#include <stdlib.h>\fP
 .sp
-.B long int random(void);
-.br
-.BI "void srandom(unsigned int " seed );
+\fBlong int random(void);\fP
 
-.BI "char *initstate(unsigned int " seed ", char *" state ", size_t " n );
+\fBvoid srandom(unsigned int \fP\fIseed\fP\fB);\fP
 
-.BI "char *setstate(char *" state );
+\fBchar *initstate(unsigned int \fP\fIseed\fP\fB, char *\fP\fIstate\fP\fB, size_t \fP\fIn\fP\fB);\fP
+.br
+\fBchar *setstate(char *\fP\fIstate\fP\fB);\fP
 .fi
 .sp
 .in -4n
-.\"O Feature Test Macro Requirements for glibc (see
-.\"O .BR feature_test_macros (7)):
-glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
-.RB ( feature_test_macros (7)
-»²¾È):
+glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
 .in
 .sp
 .ad l
-.BR random (),
-.BR srandom (),
-.BR initstate (),
-.BR setstate ():
+\fBrandom\fP(), \fBsrandom\fP(), \fBinitstate\fP(), \fBsetstate\fP():
 .RS 4
-_SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
-_XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
+_SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
 .RE
 .ad
-.\"O .SH DESCRIPTION
-.SH ÀâÌÀ
-.\"O The
-.\"O .BR random ()
-.\"O function uses a nonlinear additive feedback random
-.\"O number generator employing a default table of size 31 long integers to
-.\"O return successive pseudo-random numbers in
-.\"O the range from 0 to \fBRAND_MAX\fR.
-.\"O The period of this random number generator is very large, approximately
-.\"O .IR "16\ *\ ((2^31)\ \-\ 1)" .
-.BR random ()
-´Ø¿ô¤Ï¡¢ÈóÀþ·Á²ÃË¡¥Õ¥£¡¼¥É¥Ð¥Ã¥¯¤òÍѤ¤¤¿Íð¿ôÀ¸À®´Ø¿ô¤Ç¤¢¤ë¡£
-¤³¤Î´Ø¿ô¤Ï¡¢0 ¤«¤é \fBRAND_MAX\fR ¤Þ¤Ç¤Îµ¿»÷Íð¿ô¤òÊÖ¤¹¡£
-¤½¤Î¤¿¤á¤Ë 31 ¸Ä¤Î¥í¥ó¥°À°¿ô¤«¤é¤Ê¤ë¥Ç¥Õ¥©¥ë¥È¤Îɽ¤ò»ÈÍѤ¹¤ë¡£
-¤³¤ÎÍð¿ô¤òÀ¸À®¤¹¤ë´Ø¿ô¤Î¼þ´ü¤Ï¤È¤Æ¤âŤ¯¡¢¤ª¤è¤½
-.I "16\ *\ ((2^31)\ \-\ 1)"
-¤Ç¤¢¤ë¡£
+.SH 説明
+\fBrandom\fP()  関数は、非線形加法フィードバックを用いた乱数生成関数である。 この関数は、0 から \fBRAND_MAX\fP
+までの疑似乱数を返す。 そのために 31 個のロング整数からなるデフォルトの表を使用する。 この乱数を生成する関数の周期はとても長く、およそ \fI16\ *\ ((2^31)\ \-\ 1)\fP である。
 .PP
-.\"O The
-.\"O .BR srandom ()
-.\"O function sets its argument as the seed for a new
-.\"O sequence of pseudo-random integers to be returned by
-.\"O .BR random ().
-.\"O These sequences are repeatable by calling
-.\"O .BR srandom ()
-.\"O with the same
-.\"O seed value.
-.\"O If no seed value is provided, the
-.\"O .BR random ()
-.\"O function
-.\"O is automatically seeded with a value of 1.
-.BR srandom ()
-´Ø¿ô¤Ï¡¢
-.BR random ()
-¤ÇÊÖ¤µ¤ì¤ëµ¿»÷Íð¿ôÀ°¿ô·ÏÎó¤Î¼ï¤òÀßÄꤹ¤ë¡£
-¤½¤Î¤¿¤á¤Ë¤Ï¿·¤·¤¤¼ï¤ò°ú¿ô¤Ë¤·¤Æ
-.BR srandom ()
-¤ò¸Æ¤Ù¤Ð¤è¤¤¡£
-.BR random ()
-¤ÇÀ¸À®¤µ¤ì¤ë·ÏÎó¤Ï¡¢
-°ú¿ô¤ËƱ¤¸¼ï¤ÎÃͤòÍѤ¤¤Æ
-.BR srandom ()
-¤ò¸Æ¤Ö¤³¤È¤ÇºÆ¸½²Äǽ¤Ç¤¢¤ë¡£
-¼ï¤ÎÃͤ¬Í¿¤¨¤é¤ì¤Ê¤¤¾ì¹ç¤Ë¤Ï
-.BR random ()
-´Ø¿ô¤Ï¡¢¼«Æ°Åª¤Ë 1 ¤ò¼ï¤ËÀßÄꤹ¤ë¡£
+\fBsrandom\fP()  関数は、 \fBrandom\fP()  で返される疑似乱数整数系列の種を設定する。 そのためには新しい種を引数にして
+\fBsrandom\fP()  を呼べばよい。 \fBrandom\fP()  で生成される系列は、 引数に同じ種の値を用いて \fBsrandom\fP()
+を呼ぶことで再現可能である。 種の値が与えられない場合には \fBrandom\fP()  関数は、自動的に 1 を種に設定する。
 .PP
-.\"O The
-.\"O .BR initstate ()
-.\"O function allows a state array \fIstate\fP to
-.\"O be initialized for use by
-.\"O .BR random ().
-.\"O The size of the state array
-.\"O \fIn\fP is used by
-.\"O .BR initstate ()
-.\"O to decide how sophisticated a
-.\"O random number generator it should use \(em the larger the state array,
-.\"O the better the random numbers will be.
-.\"O \fIseed\fP is the seed for the
-.\"O initialization, which specifies a starting point for the random number
-.\"O sequence, and provides for restarting at the same point.
-.BR initstate ()
-´Ø¿ô¤Ï¡¢
-.BR random ()
-¤Ç»ÈÍѤµ¤ì¤ë¾õÂÖÇÛÎó
-\fIstate\fP ¤ò½é´ü²½¤¹¤ë¡£
-.BR initstate ()
-¤Ç¤Ï¡¢¾õÂÖÇÛÎó¤ÎÂ礭¤µ \fIn\fP ¤Ï
-»ÈÍѤ¹¤ë´Ø¿ô¤ÎÍð¿ôÀ¸À®¤ÎÀ­Ç½¤ÎÄøÅÙ¤ò·èÄꤹ¤ë¤¿¤á¤Ë»ÈÍѤµ¤ì¤ë
-\(em ¾õÂÖÇÛÎó¤¬Â礭¤¤Äø¡¢Íð¿ô¤ÎÀ­Ç½¤Ï¤è¤¯¤Ê¤ë¡£
-\fIseed\fP ¤Ï½é´ü²½¤Î¤¿¤á¤Î¼ï¤Ç¤¢¤ë¡£
-¤³¤ì¤ÏÍð¿ô·ÏÎó¤Î³«»Ï°ÌÃÖ¤ò·èÄꤹ¤ë¤â¤Î¤Ç¤¢¤ê¡¢
-¤³¤ÎÃͤò»ØÄꤹ¤ë¤³¤È¤ÇƱ°ì¤Î³«»Ï°ÌÃÖ¤«¤éÍð¿ô¤ÎÀ¸À®¤ò
-ºÆ³«¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
+\fBinitstate\fP()  関数は、 \fBrandom\fP()  で使用される状態配列 \fIstate\fP を初期化する。 \fBinitstate\fP()
+では、状態配列の大きさ \fIn\fP は 使用する関数の乱数生成の性能の程度を決定するために使用される \(em 状態配列が大きい程、乱数の性能はよくなる。
+\fIseed\fP は初期化のための種である。 これは乱数系列の開始位置を決定するものであり、 この値を指定することで同一の開始位置から乱数の生成を
+再開することができる。
 .PP
-.\"O The
-.\"O .BR setstate ()
-.\"O function changes the state array used by the
-.\"O .BR random ()
-.\"O function.
-.\"O The state array \fIstate\fP is used for
-.\"O random number generation until the next call to
-.\"O .BR initstate ()
-.\"O or
-.\"O .BR setstate ().
-.\"O \fIstate\fP must first have been initialized
-.\"O using
-.\"O .BR initstate ()
-.\"O or be the result of a previous call of
-.\"O .BR setstate ().
-.BR setstate ()
-´Ø¿ô¤Ï¡¢
-.BR random ()
-¤Ç»ÈÍѤµ¤ì¤ë¾õÂÖÇÛÎó¤òÊѹ¹¤¹¤ë¡£
-¾õÂÖÇÛÎó \fIstate\fP ¤Ï¡¢
-.BR initstate ()
-¤Þ¤¿¤Ï
-.BR setstate ()
-¤¬
-¼¡¤Ë¸Æ¤Ó½Ð¤µ¤ì¤ë¤Þ¤Ç¡¢Íð¿ô¤ÎÀ¸À®¤Ë»ÈÍѤµ¤ì¤ë¡£
-\fIstate\fP ¤Ï
-.BR initstate ()
-¤òÍѤ¤¤ÆºÇ½é¤Ë½é´ü²½¤µ¤ì¤Æ¤¤¤ë¤«¡¢
-°ÊÁ°¤Ë¸Æ¤Ó½Ð¤·¤¿
-.BR setstate ()
-¤Î·ë²Ì¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
-.\"O .SH "RETURN VALUE"
-.SH ÊÖ¤êÃÍ
-.\"O The
-.\"O .BR random ()
-.\"O function returns a value between 0 and
-.\"O .BR RAND_MAX .
-.\"O The
-.\"O .BR srandom ()
-.\"O function returns no value.
-.\"O The
-.\"O .BR initstate ()
-.\"O function returns a pointer to the previous state array.
-.\"O The
-.\"O .BR setstate ()
-.\"O function returns a pointer to the previous state array, or NULL on error.
-.BR random ()
-´Ø¿ô¤Ï 0 ¤È
-.B RAND_MAX
-¤Î´Ö¤ÎÃͤòÊÖ¤¹¡£
-.BR srandom ()
-´Ø¿ô¤ÏÃͤòÊÖ¤µ¤Ê¤¤¡£
-.BR initstate ()
-´Ø¿ô¤ÏľÁ°¤Î¾õÂÖÇÛÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
-.BR setstate ()
-´Ø¿ô¤ÏľÁ°¤Î¾õÂÖÇÛÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤·¡¢
-¥¨¥é¡¼¤Î¾ì¹ç¤Ï NULL ¤òÊÖ¤¹¡£
-.\"O .SH ERRORS
-.SH ¥¨¥é¡¼
-.TP
-.B EINVAL
-.\"O A state array of less than 8 bytes was specified to
-.\"O .BR initstate ().
-.BR initstate ()
-¤Ç8¥Ð¥¤¥È¤è¤ê¤â¾®¤µ¤¤¾õÂÖÇÛÎó¤ò»ØÄꤷ¤¿¡£
-.\"O .SH "CONFORMING TO"
-.\"O 4.3BSD
-.SH ½àµò
-4.3BSD, POSIX.1-2001.
-.\"O .SH NOTES
-.SH Ãí°Õ
-.\"O Current "optimal" values for the size of the state array \fIn\fP are
-.\"O 8, 32, 64, 128, and 256 bytes; other amounts will be rounded down to
-.\"O the nearest known amount.
-.\"O Using less than 8 bytes will cause an
-.\"O error.
-¾õÂÖÇÛÎó \fIn\fP ¤ÎÂ礭¤µ¤Î¸½ºß¤Î¡ÖºÇŬ¡×ÃͤÏ
-8¡¢32¡¢64¡¢128¡¢256 ¥Ð¥¤¥È¤Ç¤¢¤ë¡£
-¤½¤Î¾¤ÎÎ̤ò»ØÄꤷ¤¿¾ì¹ç¤Ë¤Ï¡¢»ØÄꤷ¤¿Î̤ò±Û¤¨¤Ê¤¤¾å½Ò¤ÎÃͤË
-ºÇ¤â¶á¤¤Ãͤˤʤ롣
-8 ¥Ð¥¤¥È̤Ëþ¤ÎÎ̤ò»ØÄꤷ¤¿¾ì¹ç¤Ë¤Ï¥¨¥é¡¼¤Î¸¶°ø¤È¤Ê¤ë¡£
+\fBsetstate\fP()  関数は、 \fBrandom\fP()  で使用される状態配列を変更する。 状態配列 \fIstate\fP は、
+\fBinitstate\fP()  または \fBsetstate\fP()  が 次に呼び出されるまで、乱数の生成に使用される。 \fIstate\fP は
+\fBinitstate\fP()  を用いて最初に初期化されているか、 以前に呼び出した \fBsetstate\fP()  の結果でなければならない。
+.SH 返り値
+関数 \fBrandom\fP() と \fBrand_r\fP() は 0 以上 \fBRAND_MAX\fP 以下の数を返す。
+関数 \fBsrandom\fP() は値を返さない。
 
-.\"O This function should not be used in cases where multiple threads use
-.\"O .BR random ()
-.\"O and the behavior should be reproducible.
-.\"O Use
-.\"O .BR random_r (3)
-.\"O for that purpose.
-Ê£¿ô¤Î¥¹¥ì¥Ã¥É¤¬
-.BR random ()
-¤ò»È¤¦¤è¤¦¤Ê¾õ¶·¤Ç¤Ï¡¢¤³¤Î´Ø¿ô¤ò»ÈÍѤ¹¤Ù¤­¤Ç¤Ï¤Ê¤¤¡£
-¤½¤Î¾ì¹ç¤Ë¤Ï
-.BR random_r (3)
-¤ò»È¤¦¤³¤È¡£
+関数 \fBinitstate\fP() は、変更前の状態配列へのポインタを返す。エラーの場合、 \fIerrno\fP に原因を示す値が設定される。
 
-.\"O Random-number generation is a complex topic.
-.\"O .I Numerical Recipes in C: The Art of Scientific Computing
-.\"O (William H. Press, Brian P. Flannery, Saul A. Teukolsky, William
-.\"O T. Vetterling; New York: Cambridge University Press, 2007, 3rd ed.)
-.\"O provides an excellent discussion of practical random-number generation
-.\"O issues in Chapter 7 (Random Numbers).
-Íð¿ô¤ÎÀ¸À®¤ÏÊ£»¨¤ÊÏÃÂê¤Ç¤¢¤ë¡£
-.I Numerical Recipes in C: The Art of Scientific Computing
+関数 \fBsetstate\fP() は、成功すると 0 を返す。 エラーの場合、\-1 を返し、 \fIerrno\fP にエラーの原因を示す値が設定される。
+.SH エラー
+.TP 
+\fBEINVAL\fP
+\fBsetstate\fP() の引き数 \fIstate\fP が NULL であった。
+.TP 
+\fBEINVAL\fP
+\fBinitstate\fP()  で8バイトよりも小さい状態配列を指定した。
+.SH 準拠
+4.3BSD, POSIX.1\-2001.
+.SH 注意
+状態配列 \fIn\fP の大きさの現在の「最適」値は 8、32、64、128、256 バイトである。
+その他の量を指定した場合には、指定した量を越えない上述の値に 最も近い値になる。 8 バイト未満の量を指定した場合にはエラーの原因となる。
+.PP
+複数のスレッドが \fBrandom\fP()  を使うような状況では、この関数を使用すべきではない。 その場合には \fBrandom_r\fP(3)
+を使うこと。
+.PP
+乱数の生成は複雑な話題である。 \fINumerical Recipes in C: The Art of Scientific Computing\fP
 (William H. Press, Brian P. Flannery, Saul A. Teukolsky, William
 T. Vetterling; New York: Cambridge University Press, 2007, 3rd ed.)
-¤Ç¤Ï¼ÂÍÑŪ¤ÊÍð¿ôÀ¸À®¤òÏÀÅÀ¤È¤·¤¿Í¥¤ì¤¿µÄÏÀ¤¬Âè 7 ¾Ï (Íð¿ô) ¤ÇŸ³«¤µ¤ì¤Æ¤¤¤ë¡£
-
-.\"O For a more theoretical discussion which also covers many practical issues
-.\"O in depth, see Chapter 3 (Random Numbers) in Donald E. Knuth's
-.\"O .IR "The Art of Computer Programming" ,
-.\"O volume 2 (Seminumerical Algorithms), 2nd ed.; Reading, Massachusetts:
-.\"O Addison-Wesley Publishing Company, 1981.
-¤è¤êÍýÏÀŪ¤ÊµÄÏÀ¤Ë¤Ä¤¤¤Æ¤Ï Donald E. Knuth ¤Î
-.IR "The Art of Computer Programming" ,
-volume 2 (Seminumerical Algorithms), 2nd ed.; Reading, Massachusetts:
-Addison-Wesley Publishing Company, 1981
-¤ÎÂè 3 ¾Ï (Íð¿ô) ¤ò¸«¤è¡£¤³¤³¤Ç¤Ï¡¢
-¤¿¤¯¤µ¤ó¤Î¼ÂÍÑŪ¤ÊÏÃÂê¤Ë¤Ä¤¤¤Æ¤â¿¼¤¯ÌÖÍ夵¤ì¤Æ¤¤¤ë¡£
-.\"O .SH "SEE ALSO"
-.SH ´ØÏ¢¹àÌÜ
-.BR drand48 (3),
-.BR rand (3),
-.BR random_r (3),
-.BR srand (3)
+では実用的な乱数生成を論点とした優れた議論が第 7 章 (乱数) で展開されている。
+.PP
+より理論的な議論については Donald E. Knuth の \fIThe Art of Computer Programming\fP, volume 2
+(Seminumerical Algorithms), 2nd ed.; Reading, Massachusetts: Addison\-Wesley
+Publishing Company, 1981 の第 3 章 (乱数) を見よ。ここでは、 たくさんの実用的な話題についても深く網羅されている。
+.SH バグ
+.\" http://sourceware.org/bugzilla/show_bug.cgi?id=15380
+POSIX では、エラー時に \fBinitstate\fP() は NULL を返すべきとされている。 glibc の実装では、エラー時に \fIerrno\fP
+は仕様通りに設定されるが、関数の返り値は NULL ではない。
+.SH 関連項目
+\fBdrand48\fP(3), \fBrand\fP(3), \fBrandom_r\fP(3), \fBsrand\fP(3)
+.SH この文書について
+この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.53 の一部
+である。プロジェクトの説明とバグ報告に関する情報は
+http://www.kernel.org/doc/man\-pages/ に書かれている。