Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

174 Zeilen
7.8KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <title>rand48 (The Red Hat newlib C Library)</title>
  7. <meta name="description" content="rand48 (The Red Hat newlib C Library)">
  8. <meta name="keywords" content="rand48 (The Red Hat newlib C Library)">
  9. <meta name="resource-type" content="document">
  10. <meta name="distribution" content="global">
  11. <meta name="Generator" content="makeinfo">
  12. <link href="index.html#Top" rel="start" title="Top">
  13. <link href="Document-Index.html#Document-Index" rel="index" title="Document Index">
  14. <link href="Document-Index.html#SEC_Contents" rel="contents" title="Table of Contents">
  15. <link href="Stdlib.html#Stdlib" rel="up" title="Stdlib">
  16. <link href="rpmatch.html#rpmatch" rel="next" title="rpmatch">
  17. <link href="random.html#random" rel="prev" title="random">
  18. <style type="text/css">
  19. <!--
  20. a.summary-letter {text-decoration: none}
  21. blockquote.indentedblock {margin-right: 0em}
  22. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  23. blockquote.smallquotation {font-size: smaller}
  24. div.display {margin-left: 3.2em}
  25. div.example {margin-left: 3.2em}
  26. div.lisp {margin-left: 3.2em}
  27. div.smalldisplay {margin-left: 3.2em}
  28. div.smallexample {margin-left: 3.2em}
  29. div.smalllisp {margin-left: 3.2em}
  30. kbd {font-style: oblique}
  31. pre.display {font-family: inherit}
  32. pre.format {font-family: inherit}
  33. pre.menu-comment {font-family: serif}
  34. pre.menu-preformatted {font-family: serif}
  35. pre.smalldisplay {font-family: inherit; font-size: smaller}
  36. pre.smallexample {font-size: smaller}
  37. pre.smallformat {font-family: inherit; font-size: smaller}
  38. pre.smalllisp {font-size: smaller}
  39. span.nolinebreak {white-space: nowrap}
  40. span.roman {font-family: initial; font-weight: normal}
  41. span.sansserif {font-family: sans-serif; font-weight: normal}
  42. ul.no-bullet {list-style: none}
  43. -->
  44. </style>
  45. </head>
  46. <body lang="en">
  47. <a name="rand48"></a>
  48. <div class="header">
  49. <p>
  50. Next: <a href="rpmatch.html#rpmatch" accesskey="n" rel="next">rpmatch</a>, Previous: <a href="random.html#random" accesskey="p" rel="prev">random</a>, Up: <a href="Stdlib.html#Stdlib" accesskey="u" rel="up">Stdlib</a> &nbsp; [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
  51. </div>
  52. <hr>
  53. <a name="rand48_002c-drand48_002c-erand48_002c-lrand48_002c-nrand48_002c-mrand48_002c-jrand48_002c-srand48_002c-seed48_002c-lcong48_002d_002d_002dpseudo_002drandom-number-generators-and-initialization-routines"></a>
  54. <h3 class="section">2.35 <code>rand48</code>, <code>drand48</code>, <code>erand48</code>, <code>lrand48</code>, <code>nrand48</code>, <code>mrand48</code>, <code>jrand48</code>, <code>srand48</code>, <code>seed48</code>, <code>lcong48</code>&mdash;pseudo-random number generators and initialization routines</h3>
  55. <a name="index-rand48"></a>
  56. <a name="index-drand48"></a>
  57. <a name="index-erand48"></a>
  58. <a name="index-lrand48"></a>
  59. <a name="index-nrand48"></a>
  60. <a name="index-mrand48"></a>
  61. <a name="index-jrand48"></a>
  62. <a name="index-srand48"></a>
  63. <a name="index-seed48"></a>
  64. <a name="index-lcong48"></a>
  65. <p><strong>Synopsis</strong>
  66. </p><div class="example">
  67. <pre class="example">#include &lt;stdlib.h&gt;
  68. double drand48(void);
  69. double erand48(unsigned short <var>xseed</var>[3]);
  70. long lrand48(void);
  71. long nrand48(unsigned short <var>xseed</var>[3]);
  72. long mrand48(void);
  73. long jrand48(unsigned short <var>xseed</var>[3]);
  74. void srand48(long <var>seed</var>);
  75. unsigned short *seed48(unsigned short <var>xseed</var>[3]);
  76. void lcong48(unsigned short <var>p</var>[7]);
  77. </pre></div>
  78. <p><strong>Description</strong><br>
  79. The <code>rand48</code> family of functions generates pseudo-random numbers
  80. using a linear congruential algorithm working on integers 48 bits in size.
  81. The particular formula employed is
  82. r(n+1) = (a * r(n) + c) mod m
  83. where the default values are
  84. for the multiplicand a = 0xfdeece66d = 25214903917 and
  85. the addend c = 0xb = 11. The modulo is always fixed at m = 2 ** 48.
  86. r(n) is called the seed of the random number generator.
  87. </p>
  88. <p>For all the six generator routines described next, the first
  89. computational step is to perform a single iteration of the algorithm.
  90. </p>
  91. <p><code>drand48</code> and <code>erand48</code>
  92. return values of type double. The full 48 bits of r(n+1) are
  93. loaded into the mantissa of the returned value, with the exponent set
  94. such that the values produced lie in the interval [0.0, 1.0].
  95. </p>
  96. <p><code>lrand48</code> and <code>nrand48</code>
  97. return values of type long in the range
  98. [0, 2**31-1]. The high-order (31) bits of
  99. r(n+1) are loaded into the lower bits of the returned value, with
  100. the topmost (sign) bit set to zero.
  101. </p>
  102. <p><code>mrand48</code> and <code>jrand48</code>
  103. return values of type long in the range
  104. [-2**31, 2**31-1]. The high-order (32) bits of
  105. r(n+1) are loaded into the returned value.
  106. </p>
  107. <p><code>drand48</code>, <code>lrand48</code>, and <code>mrand48</code>
  108. use an internal buffer to store r(n). For these functions
  109. the initial value of r(0) = 0x1234abcd330e = 20017429951246.
  110. </p>
  111. <p>On the other hand, <code>erand48</code>, <code>nrand48</code>, and <code>jrand48</code>
  112. use a user-supplied buffer to store the seed r(n),
  113. which consists of an array of 3 shorts, where the zeroth member
  114. holds the least significant bits.
  115. </p>
  116. <p>All functions share the same multiplicand and addend.
  117. </p>
  118. <p><code>srand48</code> is used to initialize the internal buffer r(n) of
  119. <code>drand48</code>, <code>lrand48</code>, and <code>mrand48</code>
  120. such that the 32 bits of the seed value are copied into the upper 32 bits
  121. of r(n), with the lower 16 bits of r(n) arbitrarily being set to 0x330e.
  122. Additionally, the constant multiplicand and addend of the algorithm are
  123. reset to the default values given above.
  124. </p>
  125. <p><code>seed48</code> also initializes the internal buffer r(n) of
  126. <code>drand48</code>, <code>lrand48</code>, and <code>mrand48</code>,
  127. but here all 48 bits of the seed can be specified in an array of 3 shorts,
  128. where the zeroth member specifies the lowest bits. Again,
  129. the constant multiplicand and addend of the algorithm are
  130. reset to the default values given above.
  131. <code>seed48</code> returns a pointer to an array of 3 shorts which contains
  132. the old seed.
  133. This array is statically allocated, thus its contents are lost after
  134. each new call to <code>seed48</code>.
  135. </p>
  136. <p>Finally, <code>lcong48</code> allows full control over the multiplicand and
  137. addend used in <code>drand48</code>, <code>erand48</code>, <code>lrand48</code>, <code>nrand48</code>,
  138. <code>mrand48</code>, and <code>jrand48</code>,
  139. and the seed used in <code>drand48</code>, <code>lrand48</code>, and <code>mrand48</code>.
  140. An array of 7 shorts is passed as parameter; the first three shorts are
  141. used to initialize the seed; the second three are used to initialize the
  142. multiplicand; and the last short is used to initialize the addend.
  143. It is thus not possible to use values greater than 0xffff as the addend.
  144. </p>
  145. <p>Note that all three methods of seeding the random number generator
  146. always also set the multiplicand and addend for any of the six
  147. generator calls.
  148. </p>
  149. <p>For a more powerful random number generator, see <code>random</code>.
  150. </p>
  151. <br>
  152. <p><strong>Portability</strong><br>
  153. SUS requires these functions.
  154. </p>
  155. <p>No supporting OS subroutines are required.
  156. </p>
  157. <br>
  158. <hr>
  159. <div class="header">
  160. <p>
  161. Next: <a href="rpmatch.html#rpmatch" accesskey="n" rel="next">rpmatch</a>, Previous: <a href="random.html#random" accesskey="p" rel="prev">random</a>, Up: <a href="Stdlib.html#Stdlib" accesskey="u" rel="up">Stdlib</a> &nbsp; [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
  162. </div>
  163. </body>
  164. </html>