OSDN Git Service

(split) Fixed #25191 (typo in fenv.3).
[linuxjm/LDP_man-pages.git] / release / man3 / rand.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 .\"
28 .\" Modified 1993-03-29, David Metcalfe
29 .\" Modified 1993-04-28, Lars Wirzenius
30 .\" Modified 1993-07-24, Rik Faith (faith@cs.unc.edu)
31 .\" Modified 1995-05-18, Rik Faith (faith@cs.unc.edu) to add
32 .\"          better discussion of problems with rand on other systems.
33 .\"          (Thanks to Esa Hyyti{ (ehyytia@snakemail.hut.fi).)
34 .\" Modified 1998-04-10, Nicola'O^ Lichtmaier <nick@debian.org>
35 .\"          with contribution from Francesco Potorti <F.Potorti@cnuce.cnr.it>
36 .\" Modified 2003-11-15, aeb, added rand_r
37 .\"
38 .\" Japanese Version Copyright (c) 1997 YOSHINO Takashi all rights reserved.
39 .\" Translated 1997-01-21, YOSHINO Takashi <yoshino@civil.jcn.nihon-u.ac.jp>
40 .\" Updated 2000-09-24, Kentaro Shirakata <argrath@ub32.org>
41 .\" Updated 2005-03-15, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
42 .\" Updated 2008-08-08, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.05
43 .\"
44 .TH RAND 3 2008-08-29 "" "Linux Programmer's Manual"
45 .SH Ì¾Á°
46 rand, srand \- Íð¿ô¤òÀ¸À®¤¹¤ë´Ø¿ô
47 .SH ½ñ¼°
48 .nf
49 .B #include <stdlib.h>
50 .sp
51 .B int rand(void);
52 .sp
53 .BI "int rand_r(unsigned int *" seedp );
54 .sp
55 .BI "void srand(unsigned int " seed );
56 .fi
57 .sp
58 .in -4n
59 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
60 .RB ( feature_test_macros (7)
61 »²¾È):
62 .in
63 .sp
64 .BR rand_r ():
65 _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _POSIX_SOURCE
66 .SH ÀâÌÀ
67 .BR rand ()
68 ´Ø¿ô¤Ï [0,\ \fBRAND_MAX\fR] ¤ÎÈϰϤε¿»÷Íð¿ôÀ°¿ô¤òÊÖ¤¹¡£
69 .PP
70 .BR srand ()
71 ´Ø¿ô¤Ï¡¢
72 .BR rand ()
73 ´Ø¿ô¤Çºî¤é¤ì¤ëµ¿»÷Íð¿ôÀ°¿ô·ÏÎó¤Î¿·¤·¤¤¼ï¤È¤·¤Æ¡¢
74 ¤½¤Î°ú¤­¿ô¤ÎÃͤò»ÈÍѤ¹¤ë¡£
75 ¤³¤ì¤é¤Î´Ø¿ô¤ò»ÈÍѤ·¤Æºî¤é¤ì¤¿µ¿»÷Íð¿ô·ÏÎó¤Ï¡¢
76 Ʊ¤¸Ãͤò°ú¤­¿ô¤È¤·¤Æ
77 .BR srand ()
78 ¤ò¸Æ¤Ö¤³¤È¤Ç¡¢
79 ºÆ¸½¤¹¤ë¤³¤È¤¬²Äǽ¤Ç¤¢¤ë¡£
80 .PP
81 ¼ï¤ÎÃͤ¬Í¿¤¨¤é¤ì¤Ê¤¤¾ì¹ç¤Ë¤Ï¡¢
82 .BR rand ()
83 ´Ø¿ô¤Ï
84 ¼«Æ°Åª¤Ë 1 ¤ò¼ï¤È¤¹¤ë¡£
85 .PP
86 .BR rand ()
87 ´Ø¿ô¤ÏºÆÆþ²Äǽ (reentrant) ¤Ç¤Ï¤Ê¤¤¡¢¤Ä¤Þ¤ê¥¹¥ì¥Ã¥É¡¦¥»¡¼¥Õ¤Ç¤Ï¤Ê¤¤¡£
88 ¤Ê¤¼¤Ê¤é¡¢¤³¤Î´Ø¿ô¤Ï±£¤·¾õÂÖ¤ò»ý¤Ã¤Æ¤ª¤ê¡¢¸Æ¤Ó½Ð¤µ¤ì¤ëÅÙ¤ËÊѹ¹¤¹¤ë¤«¤é¤Ç¤¢¤ë¡£
89 ¤Á¤ç¤¦¤É¤³¤Î±£¤·¾õÂÖ¤¬¼¡¤Î¸Æ¤Ó½Ð¤·»þ¤ÎÍð¿ô¤Î¼ï¤È¤·¤Æ»È¤ï¤ì¤ë¤è¤¦¤Ê¤â¤Î¤Ç¤¢¤ë¡£
90 ¼ÂºÝ¤Ë¤Ï¤â¤¦¾¯¤·Ê£»¨¤«¤â¤·¤ì¤Ê¤¤¤¬¡£¥¹¥ì¥Ã¥É¤ò»ÈÍѤ¹¤ë¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç
91 ºÆ¸½²Äǽ¤ÊÆ°ºî¤ò¤µ¤»¤¿¤¤¾ì¹ç¤Ë¤Ï¡¢¤³¤Î±£¤·¾õÂÖ¤¬¸¶°ø¤ÇºÆ¸½À­¤¬¤Ê¤¯¤Ê¤ë¡£
92 .BR rand_r ()
93 ´Ø¿ô¤Ï
94 .I unsigned int
95 ·¿¤ÎÊÑ¿ô¤Ø¤Î¥Ý¥¤¥ó¥¿¤ò°ú¤­¿ô¤Ë¤È¤ê¡¢
96 ¤³¤ÎÊÑ¿ô¤ò¾õÂÖ³ÊǼÍѤ˻ÈÍѤ¹¤ë¡£
97 ¾õÂÖ¿ô¤¬Èó¾ï¤Ë¾®¤µ¤¤¤Î¤Ç¡¢¤³¤Î´Ø¿ô¤Ï¤¢¤Þ¤ê¤è¤¤µ¼»÷Íð¿ôÀ¸À®´ï¤È¤Ï¸À¤¨¤Ê¤¤¤À¤í¤¦¡£
98 Âå¤ï¤ê¤Ë
99 .BR drand48_r (3)
100 ¤ò»È¤¦¤È¤è¤¤¡£
101 .SH ÊÖ¤êÃÍ
102 .BR rand ()
103 ¤È
104 .BR rand_r ()
105 ´Ø¿ô¤Ï 0 ¤È
106 .B RAND_MAX
107 ¤Î´Ö¤Î¿ô¤òÊÖ¤¹¡£
108 .BR srand ()
109 ´Ø¿ô¤ÏÃͤòÊÖ¤µ¤Ê¤¤¡£
110 .SH ½àµò
111 ´Ø¿ô
112 .BR rand ()
113 ¤È
114 .BR srand ()
115 ¤Ï SVr4, 4.3BSD, C89, C99, POSIX.1-2001 ¤Ë½àµò¤·¤Æ¤¤¤ë¡£
116 ´Ø¿ô
117 .BR rand_r ()
118 ¤Ï POSIX.1-2001 ¤ËͳÍ褹¤ë¡£
119 POSIX.1-2008 ¤Ï¡¢
120 .BR rand_r ()
121 ¤òÇÑ»ßͽÄê¤È¤·¤Æ¤¤¤ë¡£
122 .SH Ãí°Õ
123 .BR rand ()
124 ¤È
125 .BR srand ()
126 ¤Î Linux C Library ÈǤϡ¢
127 .BR random (3)
128 ¤È
129 .BR srandom (3)
130 ¤Îξ´Ø¿ô¤ÈƱ¤¸Íð¿ôÀ¸À®
131 ¥¢¥ë¥´¥ê¥º¥à¤ò»ÈÍѤ·¤Æ¤¤¤ë¡£¤½¤Î¤¿¤á¡¢²¼°Ì¤Î¥Ó¥Ã¥È¤Ï¾å°Ì¤Î¥Ó¥Ã¥È¤È
132 Ʊ¤¸¤¯¤é¤¤¤Ë¥é¥ó¥À¥à¤Ç¤¢¤ë¡£
133 ¤·¤«¤·¡¢µìÈǤÎ
134 .BR rand ()
135 ¤Î¼ÂÁõ¤ä¡¢Â¾¤Î¥·¥¹¥Æ¥à¤Î¸½ºß¤Î¼ÂÁõ¤Ç¤Ï¡¢²¼°Ì¤Î¥Ó¥Ã¥È¤¬¾å°Ì¤Î¥Ó¥Ã¥È¤Û¤É
136 ¥é¥ó¥À¥à¤Ë¤Ê¤Ã¤Æ¤¤¤Ê¤¤¡£°Ü¿¢À­¤ò¹â¤á¤ë¾ì¹ç¤Ç¤â¡¢ÀºÅ٤ι⤤Íð¿ô¤¬É¬ÍפÊ
137 ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï¤³¤Î´Ø¿ô¤Ï»ÈÍѤ·¤Æ¤Ï¤¤¤±¤Ê¤¤
138 (Âå¤ï¤ê¤Ë
139 .BR random (3)
140 ¤ò»È¤¦¤³¤È)¡£
141 .SH Îã
142 POSIX 1003.1-2003 ¤Ç¤Ï¡¢
143 .BR rand ()
144 ¤È
145 .BR srand ()
146 ¤Î¼ÂÁõÎã¤È¤·¤Æ°Ê²¼¤òµó¤²¤Æ¤¤¤ë¡£¤³¤ì¤Ï¡¢°Û¤Ê¤ë£²¤Ä¤Î¥Þ¥·¥ó¤ÇƱ¤¸Íð¿ô·ÏÎó¤¬
147 ɬÍפʾì¹ç¤Ë¤ÏÊØÍø¤Ç¤¢¤í¤¦¡£
148 .sp
149 .in +4n
150 .nf
151 static unsigned long next = 1;
152
153 /* RAND_MAX ¤ò 32767 ¤È²¾Äê */
154 int myrand(void) {
155     next = next * 1103515245 + 12345;
156     return((unsigned)(next/65536) % 32768);
157 }
158
159 void mysrand(unsigned seed) {
160     next = seed;
161 }
162 .fi
163 .in
164 .SH ´ØÏ¢¹àÌÜ
165 .BR drand48 (3),
166 .BR random (3)