Derived type to hold a random number generator, which does not interfere with the
global RANDOM_NUMBER()
routine of fortran.
Using t_random
can be useful when coupling software which depend on specifically
seeded random number generator for internal use, and should not clash with another.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer, | public | :: | zseed |
value of |
Create the t_random
object with a seed value zseed
. If zseed=0
, a new seed is generated
based on system_clock
values.
Call as:
type( t_random ), pointer :: rnd
integer :: zseed
! with specified value for zseed:
rnd => t_random( zseed )
! or without zseed (this is equivalent to zseed=0)
rnd => t_random()
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in), | optional | :: | zseed |
if not present, new seed is generated |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(t_random), | intent(inout) | :: | self |
re-seed the t_random
object with a specific value of zseed
.
initialize random number generator, modified from: https://gcc.gnu.org/onlinedocs/gcc-4.9.1/gfortran/RANDOM_005fSEED.html
Seed the random number generator with sequence generated from zseed.
If on input zseed = 0
then a new, repeatable seed sequence is generated.
On output, zseed
has value of actual seed used (single value), which can be
used to reproduce the actual sequence of seed elements.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(t_random), | intent(inout) | :: | self | |||
integer, | intent(inout) | :: | zseed |
Obtain a random real number z
, on range [0:1].
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(t_random), | intent(inout) | :: | self | |||
real, | intent(out) | :: | z(..) |
random[0:1], up to rank-3 |