M_random Module

NAME

M_random(3f) - [M_random::INTRO] Routines for generating random numbers and strings

SYNOPSIS

See the routines:

use M_random, only : init_random_seed_by_system_clock, &
& init_random_seed_by_dat, init_random_seed
use M_random, only : random_string, random_hex, random_int
use M_random, only : random_kiss64
use M_random, only : mtprng_state, mtprng_init_array, mtprng_rand64, &
& mtprng_rand_real1
use M_random, only : mtprng_int, mtprng_int_by_array
use M_random, only : mtprng_rand64, mtprng_rand, mtprng_rand_range
use M_random, only : mtprng_rand_real3, mtprng_rand_real2, &
& mtprng_rand_real1
use M_random, only : scramble

QUOTE

The generation of random numbers is too important to be left to chance – Robert R. Coveyou

DESCRIPTION

The M_random(3fm) module contains routines to support random number
generation. This includes supplements for the Fortran intrinsic
random_seed(3f).

SUPPLEMENTING INTRINSIC RANDOM_SEED o init_random_seed_by_system_clock(3f): initialize random_number(3f) to return a single value with system clock o init_random_seed_by_dat(3f): initialize random_number(3f) to return a single value using date_and_time(3f) o init_random_seed(3f): initialize random_number(3f) to return a single value with single integer seed like srand(3c)

o random_string(3f): create random string composed of provided characters of specified length
o random_hex(3f): create random hexadecimal string of specified length
o random_int(3f): return integer uniformly distributed in specified range

MISCELLANEOUS o random_kiss64(3f): A 64-bit KISS random number generator by George Margaglia. o scramble(3f): generate an integer array of specified size populated with a random permutation of 1 to size(array)

MERSENNE TWISTER ALGORITHM o mtprng_int(3f): Initializes the Mersenne Twister random number generator with o mtprng_int_by_array(3f): Initialize with an array of seeds

o mtprng_rand64(3f): Obtain the next 64-bit integer in the pseudo-random sequence in the range 0 to 2^32-1
o mtprng_rand(3f): Obtain the next 32-bit integer in the pseudo-random sequence in the range 0 to 2^31-1
o mtprng_rand_range(3f): Obtain a pseudo-random integer in the range [lo,hi]

o mtprng_rand_real3(3f): Obtain a pseudo-random real number .gt. 0 and .lt. 1.
o mtprng_rand_real2(3f): Obtain a pseudo-random real number .ge. 0.0 and .lt. 1.0
o mtprng_rand_real1(3f): Obtain a pseudo-random real number .ge. 0 and .le.= 1.


Derived Types

type, public ::  mtprng_state

Components

Type Visibility Attributes Name Initial
integer(kind=INT64), public, dimension(0:N-1) :: mt
integer(kind=INT32), public :: mti = -1

Functions

public function mtprng_rand(state) result(r)

Sample program:

Read more…

Arguments

Type IntentOptional Attributes Name
type(mtprng_state), intent(inout) :: state

Return Value integer(kind=INT32)

public function mtprng_rand64(state) result(r)

Sample program:

Read more…

Arguments

Type IntentOptional Attributes Name
type(mtprng_state), intent(inout) :: state

Return Value integer(kind=INT64)

public function mtprng_rand_range(state, lo, hi) result(r)

Sample program:

Read more…

Arguments

Type IntentOptional Attributes Name
type(mtprng_state), intent(inout) :: state
integer, intent(in) :: lo
integer, intent(in) :: hi

Return Value integer(kind=INT32)

public function mtprng_rand_real1(state) result(r)

Sample program:

Read more…

Arguments

Type IntentOptional Attributes Name
type(mtprng_state), intent(inout) :: state

Return Value real(kind=IEEE64)

public function mtprng_rand_real2(state) result(r)

Sample program:

Read more…

Arguments

Type IntentOptional Attributes Name
type(mtprng_state), intent(inout) :: state

Return Value real(kind=IEEE64)

public function mtprng_rand_real3(state) result(r)

Sample program:

Read more…

Arguments

Type IntentOptional Attributes Name
type(mtprng_state), intent(inout) :: state

Return Value real(kind=IEEE64)

public function random_hex(length) result(out)

Read more…

Arguments

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

Return Value character(len=:), allocatable

public function random_int(first, last) result(rand_int)

function random_int(first,last) result(rand_int)

Read more…

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: first
integer, intent(in) :: last

Return Value integer

public function random_kiss64()

Sample usage:

Read more…

Arguments

None

Return Value integer(kind=i8b)

public function random_string(chars, length) result(out)

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: chars
integer, intent(in) :: length

Return Value character(len=:), allocatable

public function scramble(number_of_values) result(array)

Sample program

Read more…

Arguments

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

Return Value integer, allocatable, (:)


Subroutines

public subroutine init_random_seed(mine)

Read more…

Arguments

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

public subroutine init_random_seed_by_dat()

Read more…

Arguments

None

public subroutine init_random_seed_by_system_clock()

Read more…

Arguments

None

public subroutine mtprng_init(seed, state)

Sample program:

Read more…

Arguments

Type IntentOptional Attributes Name
integer(kind=INT32), intent(in) :: seed
type(mtprng_state), intent(out) :: state

public subroutine mtprng_init_by_array(init_key, state)

Sample program:

Read more…

Arguments

Type IntentOptional Attributes Name
integer(kind=INT32), intent(in) :: init_key(:)
type(mtprng_state), intent(out) :: state