[Fortran] 纯文本查看 复制代码
Program www_fcode_cn
Implicit None
real :: x
integer :: i
call RANDOM_SEED()
Do i = 1 , 10 !// 10个
call RANDOM_NUMBER( x )
x = x * 2.0 - 1.0
write(*,*) x
End Do
End Program www_fcode_cn
[Fortran] 纯文本查看 复制代码
Module ran001
Implicit None
Save
Integer :: n = 9876
End Module ran001
!-------------------------------------------------------------
Subroutine random0(ran)
Use ran001
Implicit None
Real, Intent(out) :: ran
n = Mod(8121 * n + 28411, 134456) ! A number between 0 and 134455
ran = real(n) / 134456. ! Generate a number [0,1.)
End Subroutine random0
!-------------------------------------------------------------
Subroutine seed(iseed)
Use ran001
Implicit None
Integer, Intent(in) :: iseed
n = abs(iseed)
End Subroutine seed