M_random(3f) - [M_random::INTRO] Routines for generating random numbers and strings
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
The generation of random numbers is too important to be left to chance – Robert R. Coveyou
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.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer(kind=INT64), | public, | dimension(0:N-1) | :: | mt | |||
integer(kind=INT32), | public | :: | mti | = | -1 |
Sample program:
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(mtprng_state), | intent(inout) | :: | state |
Sample program:
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(mtprng_state), | intent(inout) | :: | state |
Sample program:
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(mtprng_state), | intent(inout) | :: | state | |||
integer, | intent(in) | :: | lo | |||
integer, | intent(in) | :: | hi |
Sample program:
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(mtprng_state), | intent(inout) | :: | state |
Sample program:
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(mtprng_state), | intent(inout) | :: | state |
Sample program:
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(mtprng_state), | intent(inout) | :: | state |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | length |
function random_int(first,last) result(rand_int)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | first | |||
integer, | intent(in) | :: | last |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | chars | |||
integer, | intent(in) | :: | length |
Sample program
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | number_of_values |
Sample program:
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=INT32), | intent(in) | :: | seed | |||
type(mtprng_state), | intent(out) | :: | state |
Sample program:
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=INT32), | intent(in) | :: | init_key(:) | |||
type(mtprng_state), | intent(out) | :: | state |