作者tprucj (陈囧)
看板Fortran
标题[问题] 乱数不随机(已爬文)
时间Thu Oct 4 11:43:14 2012
不好意思我是fortran新手
爬了文还是搞不太懂QAQ
我照
http://latinboy.pixnet.net/blog/post/23342072
这篇文章的程式码打
program random_test
implicit none
real*8 :: x(10)
call random_seed()
! call init_random_seed() !<- this line is for GFortran
call random_number(x)
write(*,'(F21.18)') x
end program
SUBROUTINE init_random_seed()
INTEGER :: i, n, clock
INTEGER, ALLOCATABLE :: seed(:)
call RANDOM_SEED(SIZE = n)
ALLOCATE(seed(n))
call SYSTEM_CLOCK(COUNT=clock)
seed = clock - 2047 * (/ (i - 1, i = 1, n) /)
seed = seed * 1103515245 + 2531011
call RANDOM_SEED(PUT = seed)
DEALLOCATE(seed)
END SUBROUTINE
每次执行的乱数还是都一样
到底要改哪里呢
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.218.188
1F:→ gilocustom:把注解掉的那行恢复後再试试看。 10/04 12:10
2F:→ tprucj:换成另一些值 但还是固定的 我用的是fortran 95 10/04 12:21
3F:→ gilocustom:再把call random_seed()注解掉再试试。 10/04 12:27
4F:→ gilocustom:95是标准之一,95与否无法得知你用的是哪家的编译器。 10/04 12:29
5F:→ tprucj:还是换一些值 然後是固定的 要怎麽看自己的编辑器呢 10/04 13:55
6F:→ gilocustom:假设你的编译指令是f95,试试 f95 -v 或 f95 -V 。 10/04 13:57
7F:→ tprucj:没看到这个选项耶 我用的编译器好像是Absoft Pro Fortran 10/04 14:24
8F:→ gilocustom:官网上的说明文件有提到"Output Version number(-V)"。 10/04 14:38
9F:→ gilocustom:这份程式码适度注解後测试OK的: pgf(7.0-4, 8.0-6), 10/04 14:57
10F:→ gilocustom:g95(0.91),gfortran(4.6.0)。 10/04 14:57
11F:→ tprucj:还没有用过编译器设定之类的东西 我去研究一下 谢谢你 10/04 15:24
12F:→ tprucj:我换了一个编译器後解决这个问题了 谢谢! 10/07 18:26