Module osl_rng

module osl_rng

    ! Uses
    use osl_core, wp => osl_wp, i4b => osl_i4b

    ! Types
    public type osl_rng_t
    public type osl_discrete_rnd_t

    ! Variables
    integer, public, parameter :: OSL_RNG_MZRAN = 1
    integer, private, parameter :: name_len = 25
    integer, private, parameter :: mzran_sz = 4
    integer (kind=i4b), private, parameter, dimension(mzran_sz) :: mzran_default_state = (/ 521288629, 362436069, 16163801, 1131199299 /)

    ! Subroutines and functions
    public subroutine osl_rng_init(self, type, seed)
    public subroutine osl_rng_free(self)
    public subroutine osl_rng_seed(self, seed)
    public function osl_rng_get(self)
    public function osl_rng_uniform(self)
    public function osl_rng_uniform_int(self, a, b)
    public function osl_rng_name(self)
    public function osl_rng_min(self)
    public function osl_rng_max(self)
    private subroutine mzran_init(self, seed)
    private subroutine mzran_seed(self, seed)
    private subroutine mzran_free(self)
    private function mzran_get(self) result (imz)
    private function mzran_uniform(self)
    public function osl_uniform_rnd(rng, a, b)
    public function osl_normal_rnd(rng)
    public function osl_exponential_rnd(rng, lambda)
    public function osl_gumbel_rnd(self, mu, beta)
    public subroutine osl_discrete_rnd_init(self, p)
    public function osl_discrete_rnd(self, rng)
    public subroutine osl_discrete_rnd_free(self)

end module osl_rng

Description of Types

osl_rng_t

public type osl_rng_t
    private
    integer :: type
    character (len=name_len) :: name
    integer (kind=i4b) :: min
    integer (kind=i4b) :: max
    integer (kind=i4b), dimension(:), pointer :: state => null ()
end type osl_rng_t

osl_discrete_rnd_t

public type osl_discrete_rnd_t
    private
    integer :: n
    real (kind=wp), dimension(:), pointer :: F
    integer, dimension(:), pointer :: L
end type osl_discrete_rnd_t

Description of Variables

OSL_RNG_MZRAN

integer, public, parameter :: OSL_RNG_MZRAN = 1

name_len

integer, private, parameter :: name_len = 25

mzran_sz

integer, private, parameter :: mzran_sz = 4

mzran_default_state

integer (kind=i4b), private, parameter, dimension(mzran_sz) :: mzran_default_state = (/ 521288629, 362436069, 16163801, 1131199299 /)

Description of Subroutines and Functions

osl_rng_init

public subroutine osl_rng_init(self, type, seed)
    type (osl_rng_t), intent(inout) :: self
    integer, optional, intent(in) :: type
    integer, optional, intent(in) :: seed
    ! Calls: mzran_init
end subroutine osl_rng_init

osl_rng_free

public subroutine osl_rng_free(self)
    type (osl_rng_t), intent(inout) :: self
    ! Calls: mzran_free
end subroutine osl_rng_free

osl_rng_seed

public subroutine osl_rng_seed(self, seed)
    type (osl_rng_t), intent(inout) :: self
    integer, intent(in) :: seed
    ! Calls: mzran_seed
end subroutine osl_rng_seed

osl_rng_get

public function osl_rng_get(self)
    type (osl_rng_t), intent(inout) :: self
    integer (kind=i4b) :: osl_rng_get
end function osl_rng_get

osl_rng_uniform

public function osl_rng_uniform(self)
    type (osl_rng_t), intent(inout) :: self
    real (kind=wp) :: osl_rng_uniform
end function osl_rng_uniform

osl_rng_uniform_int

public function osl_rng_uniform_int(self, a, b)
    type (osl_rng_t), intent(inout) :: self
    integer, intent(in) :: a
    integer, intent(in) :: b
    integer :: osl_rng_uniform_int
end function osl_rng_uniform_int

Return a random integer between A and B (inclusive). Internally, this function draws a uniform integer from the underlying generator, from the full range of the generator, and scales it, being careful to avoid integer overflow.

osl_rng_name

public function osl_rng_name(self)
    type (osl_rng_t), intent(in) :: self
    character (len=name_len) :: osl_rng_name
end function osl_rng_name

osl_rng_min

public function osl_rng_min(self)
    type (osl_rng_t), intent(in) :: self
    integer :: osl_rng_min
end function osl_rng_min

osl_rng_max

public function osl_rng_max(self)
    type (osl_rng_t), intent(in) :: self
    integer :: osl_rng_max
end function osl_rng_max

mzran_init

private subroutine mzran_init(self, seed)
    type (osl_rng_t), intent(inout) :: self
    integer, optional, intent(in) :: seed
    ! Calls: mzran_seed
end subroutine mzran_init

mzran_seed

private subroutine mzran_seed(self, seed)
    type (osl_rng_t), intent(inout) :: self
    integer, intent(in) :: seed
end subroutine mzran_seed

mzran_free

private subroutine mzran_free(self)
    type (osl_rng_t), intent(inout) :: self
end subroutine mzran_free

mzran_get

private function mzran_get(self) result(imz)
    type (osl_rng_t), intent(inout) :: self
    integer (kind=i4b) :: imz
end function mzran_get

mzran_uniform

private function mzran_uniform(self)
    type (osl_rng_t), intent(inout) :: self
    real (kind=wp) :: mzran_uniform
end function mzran_uniform

osl_uniform_rnd

public function osl_uniform_rnd(rng, a, b)
    type (osl_rng_t), intent(inout) :: rng
    real (kind=wp), optional, intent(in) :: a
    real (kind=wp), optional, intent(in) :: b
    real (kind=wp) :: osl_uniform_rnd
end function osl_uniform_rnd

osl_normal_rnd

public function osl_normal_rnd(rng)
    type (osl_rng_t), intent(inout) :: rng
    real (kind=wp) :: osl_normal_rnd
end function osl_normal_rnd

osl_exponential_rnd

public function osl_exponential_rnd(rng, lambda)
    type (osl_rng_t), intent(inout) :: rng
    real (kind=wp), intent(in) :: lambda
    real (kind=wp) :: osl_exponential_rnd
end function osl_exponential_rnd

osl_gumbel_rnd

public function osl_gumbel_rnd(self, mu, beta)
    type (osl_rng_t), intent(inout) :: self
    real (kind=wp), optional, intent(in) :: mu
    real (kind=wp), optional, intent(in) :: beta
    real (kind=wp) :: osl_gumbel_rnd
end function osl_gumbel_rnd

Return a draw from the Gumbel, or Type I Extreme Value, distribution with parameters MU and BETA using the inverse CDF transformation. The default values for MU and BETA are 0.0_wp and 1.0_wp, respectively, corresponding to the standard Gumbel distribution.

osl_discrete_rnd_init

public subroutine osl_discrete_rnd_init(self, p)
    type (osl_discrete_rnd_t), intent(inout) :: self
    real (kind=wp), dimension(:), intent(in) :: p
end subroutine osl_discrete_rnd_init

osl_discrete_rnd

public function osl_discrete_rnd(self, rng)
    type (osl_discrete_rnd_t), intent(inout) :: self
    type (osl_rng_t), intent(inout) :: rng
    real (kind=wp) :: osl_discrete_rnd
end function osl_discrete_rnd

osl_discrete_rnd_free

public subroutine osl_discrete_rnd_free(self)
    type (osl_discrete_rnd_t), intent(inout) :: self
end subroutine osl_discrete_rnd_free