mod_random Module

Module for pseudo random number generation. The internal pseudo random generator is the xoroshiro128plus method.


Used by

  • module~~mod_random~~UsedByGraph module~mod_random mod_random module~mod_particle_base mod_particle_base module~mod_particle_base->module~mod_random module~mod_particle_advect mod_particle_advect module~mod_particle_advect->module~mod_particle_base module~mod_particle_gca mod_particle_gca module~mod_particle_gca->module~mod_particle_base module~mod_particle_lorentz mod_particle_lorentz module~mod_particle_lorentz->module~mod_particle_base module~mod_particle_sample mod_particle_sample module~mod_particle_sample->module~mod_particle_base module~mod_particles mod_particles module~mod_particles->module~mod_particle_base module~mod_particles->module~mod_particle_advect module~mod_particles->module~mod_particle_gca module~mod_particles->module~mod_particle_lorentz module~mod_particles->module~mod_particle_sample module~mod_point_searching mod_point_searching module~mod_point_searching->module~mod_particle_base proc~advance advance proc~advance->module~mod_particles proc~main main proc~main->module~mod_particles proc~resettree resettree proc~resettree->module~mod_particles proc~saveamrfile saveamrfile proc~saveamrfile->module~mod_particles proc~timeintegration timeintegration proc~timeintegration->module~mod_particles

Variables

Type Visibility Attributes Name Initial
integer, private, parameter :: dp = kind(0.0d0)
integer, private, parameter :: i4 = selected_int_kind(9)
integer, private, parameter :: i8 = selected_int_kind(18)

Derived Types

type, public ::  prng_t

Parallel random number generator type

Components

Type Visibility Attributes Name Initial
type(rng_t), public, allocatable :: rngs(:)

Type-Bound Procedures

procedure, public, non_overridable :: init_parallel

type, public ::  rng_t

Random number generator type, which contains the state

Components

Type Visibility Attributes Name Initial
integer(kind=i8), private :: s(2) = [123456789_i8, 987654321_i8]

The rng state (always use your own seed)

Type-Bound Procedures

procedure, public, non_overridable :: circle
procedure, public, non_overridable :: int_4
procedure, public, non_overridable :: int_8
procedure, public, non_overridable :: jump
procedure, public, non_overridable :: next
procedure, public, non_overridable :: normal
procedure, public, non_overridable :: poisson
procedure, public, non_overridable :: set_seed
procedure, public, non_overridable :: sphere
procedure, public, non_overridable :: two_normals
procedure, public, non_overridable :: unif_01
procedure, public, non_overridable :: unif_01_vec

Functions

private function circle(self, radius) result(xy)

Sample point on a circle with given radius

Arguments

Type IntentOptional Attributes Name
class(rng_t), intent(inout) :: self
real(kind=dp), intent(in) :: radius

Return Value real(kind=dp), (2)

private function int_4(self)

Return 4-byte integer

Arguments

Type IntentOptional Attributes Name
class(rng_t), intent(inout) :: self

Return Value integer(kind=i4)

private function int_8(self)

Return 8-byte integer

Arguments

Type IntentOptional Attributes Name
class(rng_t), intent(inout) :: self

Return Value integer(kind=i8)

private function next(self) result(res)

Interal routine: get the next value (returned as 64 bit signed integer)

Arguments

Type IntentOptional Attributes Name
class(rng_t), intent(inout) :: self

Return Value integer(kind=i8)

private function normal(self)

Single normal random number

Arguments

Type IntentOptional Attributes Name
class(rng_t), intent(inout) :: self

Return Value real(kind=dp)

private function poisson(self, lambda) result(rr)

Return Poisson random variate with rate lambda. Works well for lambda < 30 or so. For lambda >> 1 it can produce wrong results due to roundoff error.

Arguments

Type IntentOptional Attributes Name
class(rng_t), intent(inout) :: self
real(kind=dp), intent(in) :: lambda

Return Value integer(kind=i4)

private pure function rotl(x, k) result(res)

Helper function for next()

Arguments

Type IntentOptional Attributes Name
integer(kind=i8), intent(in) :: x
integer, intent(in) :: k

Return Value integer(kind=i8)

private pure function shiftl(val, shift) result(res_value)

added for nvidia compilers

Arguments

Type IntentOptional Attributes Name
integer(kind=i8), intent(in) :: val
integer, intent(in) :: shift

Return Value integer(kind=i8)

private pure function shiftr(val, shift) result(res_value)

Arguments

Type IntentOptional Attributes Name
integer(kind=i8), intent(in) :: val
integer, intent(in) :: shift

Return Value integer(kind=i8)

private function sphere(self, radius) result(xyz)

Sample point on a sphere with given radius

Arguments

Type IntentOptional Attributes Name
class(rng_t), intent(inout) :: self
real(kind=dp), intent(in) :: radius

Return Value real(kind=dp), (3)

private function two_normals(self) result(rands)

Return two normal random variates with mean 0 and variance 1. http://en.wikipedia.org/wiki/Marsaglia_polar_method

Arguments

Type IntentOptional Attributes Name
class(rng_t), intent(inout) :: self

Return Value real(kind=dp), (2)

private function unif_01(self)

Get a uniform [0,1) random real (double precision)

Arguments

Type IntentOptional Attributes Name
class(rng_t), intent(inout) :: self

Return Value real(kind=dp)


Subroutines

private subroutine init_parallel(self, n_proc, rng)

Initialize a collection of rng's for parallel use

Arguments

Type IntentOptional Attributes Name
class(prng_t), intent(inout) :: self
integer, intent(in) :: n_proc
type(rng_t), intent(inout) :: rng

private subroutine jump(self)

Arguments

Type IntentOptional Attributes Name
class(rng_t), intent(inout) :: self

private subroutine set_seed(self, the_seed)

Set a seed for the rng

Arguments

Type IntentOptional Attributes Name
class(rng_t), intent(inout) :: self
integer(kind=i8), intent(in) :: the_seed(2)

private subroutine unif_01_vec(self, rr)

Fill array with uniform random numbers

Arguments

Type IntentOptional Attributes Name
class(rng_t), intent(inout) :: self
real(kind=dp), intent(out) :: rr(:)