产生的随机数不随机。
产生1~100的随机数,统计结果如下,第一个区间少了一块。不知道是哪里有问题。program random
implicit none
real :: x
integer :: up
open(7,file='randnums.txt')
call random_seed()
write(*,*) "输入随机数上限:"
read(*,*) up
do while(.true.)
call random_number(x)
x = floor((up-1)*x)+1
write(7,*) x
end do
end program random
感觉应该是统计有问题,0点。。这样画的话感觉没有明显的劣势
x = floor((up-1)*x)+1
改为
x = floor(up*x)+1
页:
[1]