set_seed Subroutine

private subroutine set_seed(this, seed)

Set initial seed of a mt19937_type instance

Set initial seeds to mt[N] using the generator Line 25 of Table 1 in [KNUTH 1981, The Art of Computer Programming Vol. 2 (2nd Ed.), pp102]

Type Bound

mt19937_type

Arguments

Type IntentOptional Attributes Name
class(mt19937_type), intent(inout) :: this
integer, intent(in) :: seed

Contents

Source Code


Source Code

  subroutine set_seed(this, seed)
    class(mt19937_type), intent(inout) :: this
    integer, intent(in) :: seed
    this%mt(0) = iand(seed, -1)
    associate(mti => this%mti)
      do mti = 1, N_mt19937 - 1
        this%mt(mti) = iand(69069 * this%mt(mti - 1), -1)
      end do
    end associate
    ! Explicitly make sure this is set, as loop index may be undefined
    this%mti = N_mt19937
  end subroutine set_seed