看板 Fortran 關於我們 聯絡資訊
不好意思我是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
gilocustom:把註解掉的那行恢復後再試試看。 10/04 12:10
tprucj:換成另一些值 但還是固定的 我用的是fortran 95 10/04 12:21
gilocustom:再把call random_seed()註解掉再試試。 10/04 12:27
gilocustom:95是標準之一,95與否無法得知你用的是哪家的編譯器。 10/04 12:29
tprucj:還是換一些值 然後是固定的 要怎麼看自己的編輯器呢 10/04 13:55
gilocustom:假設你的編譯指令是f95,試試 f95 -v 或 f95 -V 。 10/04 13:57
tprucj:沒看到這個選項耶 我用的編譯器好像是Absoft Pro Fortran 10/04 14:24
gilocustom:官網上的說明文件有提到"Output Version number(-V)"。 10/04 14:38
gilocustom:這份程式碼適度註解後測試OK的: pgf(7.0-4, 8.0-6), 10/04 14:57
gilocustom:g95(0.91),gfortran(4.6.0)。 10/04 14:57
tprucj:還沒有用過編譯器設定之類的東西 我去研究一下 謝謝你 10/04 15:24
tprucj:我換了一個編譯器後解決這個問題了 謝謝! 10/07 18:26