ran Module

A wrapper module for random number generator. This module provides real function ranf using intrinsic random_number/random_seed or Mersenne Twister 19937 (see mt19937.f90).


Contents


Functions

public function ranf(seed)

Returns a pseudorandom number range in [0., 1.), (i.e. 0<= ranf < 1). The generator is initialized with the given seed if passed, otherwise uses the seed already set (default or otherwise).

Arguments

Type IntentOptional Attributes Name
integer, intent(in), optional :: seed

Return Value real

public function get_rnd_seed_length() result(l)

Gets the length of the integer vector for the random number generator seed. This is always 1 for the Mersenne case but otherwise depends on the compiler version.

Arguments

None

Return Value integer

private function create_seed_from_single_integer(initial_seed) result(seed)

Returns an array of integers to use as a seed to the random number generator given a single integer as input.

Read more…

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: initial_seed

Return Value integer, dimension(:), allocatable

private function lcg(s)

Simple PRNG derived from gfortran documentation Intended to be used to seed a better PRNG. Probably shouldn't be used directly (hence why this is not public).

Read more…

Arguments

Type IntentOptional Attributes Name
integer(kind=kind_id), intent(inout) :: s

Return Value integer


Subroutines

public subroutine get_rnd_seed(seed)

Returns the current value of the generator seed. This is not currently supported by the Mersenne generator so in this case we return 0.

Arguments

Type IntentOptional Attributes Name
integer, intent(out), dimension(:) :: seed

public subroutine init_ranf(randomize, init_seed)

Seed the choosen random number generator. If randomize=T, a random seed based on date and time is used. (this randomizing procedure is proposed in GNU gfortran manual.) Otherwise, it sets the seed using init_seed In either case, it sets init_seed to the initial seed used on return.

Arguments

Type IntentOptional Attributes Name
logical, intent(in) :: randomize
integer, intent(inout), dimension(:) :: init_seed

public subroutine set_seed_from_single_integer(initial_seed)

Sets the seed for the random number generator provided by the standard based on a single integer. We use create_seed_from_single_integer to ensure we have enough values in the series rather than just duplicating this number.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: initial_seed