]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/fortran/doc/gfortran/intrinsic-procedures/randominit.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / fortran / doc / gfortran / intrinsic-procedures / randominit.rst
1 ..
2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
5
6 .. index:: RANDOM_INIT, random number generation, initialization
7
8 .. _random_init:
9
10 RANDOM_INIT --- Initialize a pseudo-random number generator
11 ***********************************************************
12
13 .. function:: RANDOM_INIT(REPEATABLE, IMAGE_DISTINCT)
14
15 Initializes the state of the pseudorandom number generator used by
16 ``RANDOM_NUMBER``.
17
18 :param REPEATABLE:
19 Shall be a scalar with a ``LOGICAL`` type,
20 and it is ``INTENT(IN)``. If it is ``.true.``, the seed is set to
21 a processor-dependent value that is the same each time ``RANDOM_INIT``
22 is called from the same image. The term 'same image' means a single
23 instance of program execution. The sequence of random numbers is different
24 for repeated execution of the program. If it is ``.false.``, the seed
25 is set to a processor-dependent value.
26
27 :param IMAGE_DISTINCT:
28 Shall be a scalar with a
29 ``LOGICAL`` type, and it is ``INTENT(IN)``. If it is ``.true.``,
30 the seed is set to a processor-dependent value that is distinct from th
31 seed set by a call to ``RANDOM_INIT`` in another image. If it is
32 ``.false.``, the seed is set to a value that does depend which image called
33 ``RANDOM_INIT``.
34
35 Standard:
36 Fortran 2018
37
38 Class:
39 Subroutine
40
41 Syntax:
42 .. code-block:: fortran
43
44 CALL RANDOM_INIT(REPEATABLE, IMAGE_DISTINCT)
45
46 Example:
47 .. code-block:: fortran
48
49 program test_random_seed
50 implicit none
51 real x(3), y(3)
52 call random_init(.true., .true.)
53 call random_number(x)
54 call random_init(.true., .true.)
55 call random_number(y)
56 ! x and y are the same sequence
57 if (any(x /= y)) call abort
58 end program test_random_seed
59
60 See also:
61 :ref:`RANDOM_NUMBER`,
62 :ref:`RANDOM_SEED`