在fortran中rand()的用法是怎样的?麻烦举个例子

来源:百度知道 编辑:UC知道 时间:2024/06/22 03:05:37

rand()不大好用,用这个:
0-1之间类似于

program test
implicit none
real :: x
call random_seed()! 系统根据日期和时间随机地提供种子"
call random_number(x)
print *,x
end program

另外,在一个程序中, "call random_seed () 这一句是不能重复的,只能用一次。
所以它不能放到循环里面去,另外,如果一个子程序会被调用多次的话,也不能放到子程序里面。

==============
如果你非得用rand()的话,看看这个帖子吧:
http://bbs.pfan.cn/post-276179.html

c--
c rand.f: A sample program to generate a pseudorandom number sequence.
c This program prints ten numbers between 0.0 and 1.0, and it also
c prints a different sequence each time (unless you run it a LOT of
c times---the rand() functon is, after all, only pseudorandom).
c--
program rand
real rand ! Declare the type of the rand() function
integer i ! Counts random numbers
integer