RANDOM_005fSEED.html 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1999-2017 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>The GNU Fortran Compiler: RANDOM_SEED</title>
  20. <meta name="description" content="The GNU Fortran Compiler: RANDOM_SEED">
  21. <meta name="keywords" content="The GNU Fortran Compiler: RANDOM_SEED">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Intrinsic-Procedures.html#Intrinsic-Procedures" rel="up" title="Intrinsic Procedures">
  30. <link href="RANGE.html#RANGE" rel="next" title="RANGE">
  31. <link href="RANDOM_005fNUMBER.html#RANDOM_005fNUMBER" rel="prev" title="RANDOM_NUMBER">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style:oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="RANDOM_005fSEED"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="RANGE.html#RANGE" accesskey="n" rel="next">RANGE</a>, Previous: <a href="RANDOM_005fNUMBER.html#RANDOM_005fNUMBER" accesskey="p" rel="prev">RANDOM_NUMBER</a>, Up: <a href="Intrinsic-Procedures.html#Intrinsic-Procedures" accesskey="u" rel="up">Intrinsic Procedures</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  66. </div>
  67. <hr>
  68. <a name="RANDOM_005fSEED-_002d_002d_002d-Initialize-a-pseudo_002drandom-number-sequence"></a>
  69. <h3 class="section">9.223 <code>RANDOM_SEED</code> &mdash; Initialize a pseudo-random number sequence</h3>
  70. <a name="index-RANDOM_005fSEED"></a>
  71. <a name="index-random-number-generation_002c-seeding"></a>
  72. <a name="index-seeding-a-random-number-generator"></a>
  73. <dl compact="compact">
  74. <dt><em>Description</em>:</dt>
  75. <dd><p>Restarts or queries the state of the pseudorandom number generator used by
  76. <code>RANDOM_NUMBER</code>.
  77. </p>
  78. <p>If <code>RANDOM_SEED</code> is called without arguments, it is seeded with
  79. random data retrieved from the operating system.
  80. </p>
  81. <p>As an extension to the Fortran standard, the GFortran
  82. <code>RANDOM_NUMBER</code> supports multiple threads. Each thread in a
  83. multi-threaded program has its own seed. When <code>RANDOM_SEED</code> is
  84. called either without arguments or with the <var>PUT</var> argument, the
  85. given seed is copied into a master seed as well as the seed of the
  86. current thread. When a new thread uses <code>RANDOM_NUMBER</code> for the
  87. first time, the seed is copied from the master seed, and forwarded
  88. <em>N * 2^{512}</em> steps to guarantee that the random stream does not
  89. alias any other stream in the system, where <var>N</var> is the number of
  90. threads that have used <code>RANDOM_NUMBER</code> so far during the program
  91. execution.
  92. </p>
  93. </dd>
  94. <dt><em>Standard</em>:</dt>
  95. <dd><p>Fortran 95 and later
  96. </p>
  97. </dd>
  98. <dt><em>Class</em>:</dt>
  99. <dd><p>Subroutine
  100. </p>
  101. </dd>
  102. <dt><em>Syntax</em>:</dt>
  103. <dd><p><code>CALL RANDOM_SEED([SIZE, PUT, GET])</code>
  104. </p>
  105. </dd>
  106. <dt><em>Arguments</em>:</dt>
  107. <dd><table>
  108. <tr><td width="15%"><var>SIZE</var></td><td width="70%">(Optional) Shall be a scalar and of type default
  109. <code>INTEGER</code>, with <code>INTENT(OUT)</code>. It specifies the minimum size
  110. of the arrays used with the <var>PUT</var> and <var>GET</var> arguments.</td></tr>
  111. <tr><td width="15%"><var>PUT</var></td><td width="70%">(Optional) Shall be an array of type default
  112. <code>INTEGER</code> and rank one. It is <code>INTENT(IN)</code> and the size of
  113. the array must be larger than or equal to the number returned by the
  114. <var>SIZE</var> argument.</td></tr>
  115. <tr><td width="15%"><var>GET</var></td><td width="70%">(Optional) Shall be an array of type default
  116. <code>INTEGER</code> and rank one. It is <code>INTENT(OUT)</code> and the size
  117. of the array must be larger than or equal to the number returned by
  118. the <var>SIZE</var> argument.</td></tr>
  119. </table>
  120. </dd>
  121. <dt><em>Example</em>:</dt>
  122. <dd><div class="smallexample">
  123. <pre class="smallexample">program test_random_seed
  124. implicit none
  125. integer, allocatable :: seed(:)
  126. integer :: n
  127. call random_seed(size = n)
  128. allocate(seed(n))
  129. call random_seed(get=seed)
  130. write (*, *) seed
  131. end program test_random_seed
  132. </pre></div>
  133. </dd>
  134. <dt><em>See also</em>:</dt>
  135. <dd><p><a href="RANDOM_005fNUMBER.html#RANDOM_005fNUMBER">RANDOM_NUMBER</a>
  136. </p></dd>
  137. </dl>
  138. <hr>
  139. <div class="header">
  140. <p>
  141. Next: <a href="RANGE.html#RANGE" accesskey="n" rel="next">RANGE</a>, Previous: <a href="RANDOM_005fNUMBER.html#RANDOM_005fNUMBER" accesskey="p" rel="prev">RANDOM_NUMBER</a>, Up: <a href="Intrinsic-Procedures.html#Intrinsic-Procedures" accesskey="u" rel="up">Intrinsic Procedures</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  142. </div>
  143. </body>
  144. </html>