mt19937 Derived Type

type, public :: mt19937

main class for random number generator


Contents

Source Code


Components

TypeVisibilityAttributesNameInitial
integer(kind=i8), public :: mt(nn) =0_i8

array for the state vector

integer, public :: mti =nn+1

mti==nn+1 means mt(nn) is not initialized


Type-Bound Procedures

generic, public :: initialize => init_genrand64_i4, init_genrand64, init_by_array64

call first to initialize

  • private subroutine init_genrand64_i4(me, seed)

    Initializes me%mt(nn) with a seed

    Arguments

    TypeIntentOptionalAttributesName
    class(mt19937), intent(inout) :: me
    integer(kind=i4), intent(in) :: seed
  • private subroutine init_genrand64(me, seed)

    Initializes me%mt(nn) with a seed

    Arguments

    TypeIntentOptionalAttributesName
    class(mt19937), intent(inout) :: me
    integer(kind=i8), intent(in) :: seed
  • private subroutine init_by_array64(me, init_key)

    Initializes by an array with array-length init_key is the array for initializing keys

    Arguments

    TypeIntentOptionalAttributesName
    class(mt19937), intent(inout) :: me
    integer(kind=i8), intent(in) :: init_key(:)

procedure, public :: init_genrand64

  • private subroutine init_genrand64(me, seed)

    Initializes me%mt(nn) with a seed

    Arguments

    TypeIntentOptionalAttributesName
    class(mt19937), intent(inout) :: me
    integer(kind=i8), intent(in) :: seed

procedure, public :: init_by_array64

  • private subroutine init_by_array64(me, init_key)

    Initializes by an array with array-length init_key is the array for initializing keys

    Arguments

    TypeIntentOptionalAttributesName
    class(mt19937), intent(inout) :: me
    integer(kind=i8), intent(in) :: init_key(:)

procedure, public :: init_genrand64_i4

  • private subroutine init_genrand64_i4(me, seed)

    Initializes me%mt(nn) with a seed

    Arguments

    TypeIntentOptionalAttributesName
    class(mt19937), intent(inout) :: me
    integer(kind=i4), intent(in) :: seed

procedure, public :: genrand64_real1

  • private function genrand64_real1(me)

    Generates a random number on [0,1]-real-interval

    Arguments

    TypeIntentOptionalAttributesName
    class(mt19937), intent(inout) :: me

    Return Value real(kind=r8)

procedure, public :: genrand64_real2

  • private function genrand64_real2(me)

    Generates a random number on [0,1)-real-interval

    Arguments

    TypeIntentOptionalAttributesName
    class(mt19937), intent(inout) :: me

    Return Value real(kind=r8)

procedure, public :: genrand64_real3

  • private function genrand64_real3(me)

    Generates a random number on (0,1)-real-interval

    Arguments

    TypeIntentOptionalAttributesName
    class(mt19937), intent(inout) :: me

    Return Value real(kind=r8)

procedure, public :: genrand64_int64

  • private function genrand64_int64(me)

    Generates a random number on [-2^63, 2^63-1]-interval

    Arguments

    TypeIntentOptionalAttributesName
    class(mt19937), intent(inout) :: me

    Return Value integer(kind=r8)

Source Code

  type,public :: mt19937

    !! main class for random number generator

    private

    integer(i8) :: mt(nn) = 0_i8       !! array for the state vector
    integer     :: mti = nn+1          !! `mti==nn+1` means `mt(nn)` is not initialized

    contains

    private

    generic,public :: initialize => init_genrand64_i4, &
                                    init_genrand64, &
                                    init_by_array64 !! call first to initialize
    procedure :: init_genrand64
    procedure :: init_by_array64
    procedure :: init_genrand64_i4

    procedure, public :: genrand64_real1
    procedure, public :: genrand64_real2
    procedure, public :: genrand64_real3
    procedure, public :: genrand64_int64

  end type mt19937