libSUFR
a LIBrary of Some Useful Fortran Routines
All Classes Namespaces Files Functions Variables Pages
sufr_random_numbers Module Reference

Procedures to generate random numbers. More...

Functions/Subroutines

integer function get_ran_seed (degree, date_array)
 Use the system clock to get a random initialisation seed (i.e., negative integer) for a random-numbed generator.
 
real(double) function ran_unif (seed)
 Generate a pseudo-random number from a uniform distribution 0 < r < 1.
 
real(double) function ran_gauss (seed)
 Generate a pseudo-random number from a Gaussian distribution with mean 0 and standard deviation 1.
 
subroutine ran_str (seed, str)
 Generate a pseudo-random number from a uniform distribution 0 < r < 1.
 

Detailed Description

Procedures to generate random numbers.

Function/Subroutine Documentation

◆ get_ran_seed()

integer function sufr_random_numbers::get_ran_seed ( integer, intent(in) degree,
integer, dimension(8), intent(in), optional date_array )

Use the system clock to get a random initialisation seed (i.e., negative integer) for a random-numbed generator.

Parameters
degreeDegree of randomness: 0-completely (same result for a ms), 1-same result during a clock hour, 2-same result during a calendar day (int)
date_arrayProvide a date/time array as provided by date_and_time() to generate a non-random seed, e.g. for reproduction purposes ([year,month,day, (tz), hour,minute,second,millisecond]; optional)
Return values
get_ran_seedRandon-number seed: -1e6 < seed < 0 (int)

Definition at line 40 of file random_numbers.f90.

References get_ran_seed().

Referenced by sufr_system::execute_command_line_and_return_str(), and get_ran_seed().

Here is the call graph for this function:

◆ ran_gauss()

real(double) function sufr_random_numbers::ran_gauss ( integer, intent(inout) seed)

Generate a pseudo-random number from a Gaussian distribution with mean 0 and standard deviation 1.

Parameters
seedThe seed to generate the random number from
Return values
ran_gaussThe random number, using a Gaussian distribution
  • Two pseudo-random numbers are drawn from a uniform distribution, using ran_unif().
  • These are converted into two pseudo-random numbers from a Gaussian distribution using the Box-Muller transform
  • Odd-numbered calls return the first, even-numbered calls the second number
    • using the polar form is ~38% faster than using the basic form
See also
e.g.:

Definition at line 148 of file random_numbers.f90.

References sufr_kinds::double, ran_gauss(), and ran_unif().

Referenced by ran_gauss().

Here is the call graph for this function:

◆ ran_str()

subroutine sufr_random_numbers::ran_str ( integer, intent(inout) seed,
character, dimension(*), intent(inout) str )

Generate a pseudo-random number from a uniform distribution 0 < r < 1.

Parameters
seedThe seed to generate the random number from.
Set seed<0 to initialise the generator; seed is updated between calls (int).
strThe random string (I/O: output str has length of input str, filled with random characters)

Definition at line 188 of file random_numbers.f90.

References ran_unif().

Here is the call graph for this function:

◆ ran_unif()

real(double) function sufr_random_numbers::ran_unif ( integer, intent(inout) seed)

Generate a pseudo-random number from a uniform distribution 0 < r < 1.

Parameters
seedThe seed to generate the random number from.
Set seed<0 to initialise the generator; seed is updated between calls (int).
Return values
ran_unifThe random number, uniformely generated between 0 < r < 1 (double).
  • Use two L'Ecuyer generators, period is $ \sim 10^{18}$
  • tab is a Bays-Durham shuffle table of length Ntab
    See also
    Numerical Recipes in Fortran 77, Sect.7.1.

Definition at line 80 of file random_numbers.f90.

References sufr_kinds::dbl, sufr_kinds::double, and ran_unif().

Referenced by sufr_system::execute_command_line_and_return_str(), ran_gauss(), ran_str(), and ran_unif().

Here is the call graph for this function: