[Fortran] 纯文本查看 复制代码
Subroutine ran3(idum, rand)
Implicit Real *8(A-H, M, O-Z)
Parameter (mbig=4000000., mseed=1618033., mz=0., fac=1./mbig)
Dimension ma(55)
Data iff/0/
If (idum<0 .Or. iff==0) Then
iff = 1
mj = mseed - dble(iabs(idum))
mj = dmod(mj, mbig)
ma(55) = mj
mk = 1
Do i = 1, 54
ii = mod(21*i, 55)
ma(ii) = mk
mk = mj - mk
If (mk<mz) mk = mk + mbig
mj = ma(ii)
End Do
Do k = 1, 4
Do i = 1, 55
ma(i) = ma(i) - ma(1+mod(i+30,55))
If (ma(i)<mz) ma(i) = ma(i) + mbig
End Do
End Do
! End If
inext = 0
inextp = 31
idum = 1
End If
inext = inext + 1
If (inext==56) inext = 1
inextp = inextp + 1
If (inextp==56) inextp = 1
mj = ma(inext) - ma(inextp) !!!调试时 显示在这行出错误,
If (mj<mz) mj = mj + mbig
ma(inext) = mj
rand = mj*fac
Return
End Subroutine ran3