Generates a random number on [-2^63, 2^63-1]-interval
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(mt19937), | intent(inout) | :: | me |
integer(r8) function genrand64_int64(me)
!! Generates a random number on [-2^63, 2^63-1]-interval
implicit none
class(mt19937),intent(inout) :: me
integer(i8),parameter :: mag01(0:1) = [0_i8, matrix_a]
integer(i8) :: x
integer :: i
if(me%mti >= nn) then ! generate nn words at one time
! if init_genrand64() has not been called, a default initial seed is used
if(me%mti == nn+1) call me%init_genrand64(seed_def)
do i = 1, nn-mm
x = ior(iand(me%mt(i),um), iand(me%mt(i+1), lm))
me%mt(i) = ieor(ieor(me%mt(i+mm), ishft(x, -1)), mag01(iand(x, 1_i8)))
end do
do i = nn-mm+1, nn-1
x = ior(iand(me%mt(i), um), iand(me%mt(i+1), lm))
me%mt(i) = ieor(ieor(me%mt(i+mm-nn), ishft(x, -1)), mag01(iand(x, 1_i8)))
end do
x = ior(iand(me%mt(nn), um), iand(me%mt(1), lm))
me%mt(nn) = ieor(ieor(me%mt(mm), ishft(x, -1)), mag01(iand(x, 1_i8)))
me%mti = 0
end if
me%mti = me%mti + 1
x = me%mt(me%mti)
x = ieor(x, iand(ishft(x,-29), 6148914691236517205_i8))
x = ieor(x, iand(ishft(x, 17), 8202884508482404352_i8))
x = ieor(x, iand(ishft(x, 37), -2270628950310912_i8))
x = ieor(x, ishft(x, -43))
genrand64_int64 = x
end function genrand64_int64