[UP]


Manual Reference Pages  - init_random_seed (3)

NAME

init_random_seed(3f) - [M_random] seed random_number(3f) with single value like srand(3c) usage (LICENSE:MIT)

CONTENTS

Synopsis
Description
Example
Author
License

SYNOPSIS

subroutine init_random_seed(mine)

    integer,intent(in) :: mine

DESCRIPTION

A simple wrapper around random_seed(3f) that uses the single given integer to initialize the seed so you can easily call random_number(3f) with varying pseudo-random real number sequences simply, much like srand(3c) and rand(3c).

EXAMPLE

Sample program:

    program demo_init_random_seed
    use M_random, only : init_random_seed
    integer :: iseed
    integer :: i
    real    :: x
       iseed=218595421
       call init_random_seed(iseed)
       do i=1,10
          ! generate real pseudo-random numbers from 0 to <1.0
          call random_number(x)
          write(*,*)i,x
       enddo
    end program demo_init_random_seed

Results

     >     1  0.989341617
     >     2  0.296594143
     >     3  0.805420995
     >     4   4.00894880E-03
     >     5   5.73359132E-02
     >     6  0.805290103
     >     7  0.944527864
     >     8  0.789443851
     >     9  0.327288270
     >    10  0.710926533

AUTHOR

John S. Urban

LICENSE

MIT License


init_random_seed (3) October 17, 2020
Generated by manServer 1.08 from bac5f748-986a-4718-9fc7-0d378fecdae4 using man macros.