Fortran Coder

标题: 产生的随机数不随机。 [打印本页]

作者: ID0577775606    时间: 2016-5-18 23:56
标题: 产生的随机数不随机。
产生1~100的随机数,统计结果如下,第一个区间少了一块。不知道是哪里有问题。
[Fortran] 纯文本查看 复制代码

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






Graph1.jpg (688.26 KB, 下载次数: 217)

Graph1.jpg

作者: ID0577775606    时间: 2016-5-19 00:41
感觉应该是统计有问题,0点。。这样画的话感觉没有明显的劣势

作者: fcode    时间: 2016-5-19 08:25
x = floor((up-1)*x)+1
改为
x = floor(up*x)+1




欢迎光临 Fortran Coder (http://bbs.fcode.cn/) Powered by Discuz! X3.2