產生亂數之副程式(劉老師計程班第七次作業)
subroutine random(n,seed)
implicit real (a-h,o-z)
pi=3.1416
x=(seed+pi)**5
xint=int(x)
xi=x-xint
seed=xi
n=int(seed*10)
return
stop
end
將以上的程式附在程式的某處
使用時只要call random(n,seed)
n即是0~9的整數
第一次使用時最好在call副程式前 先給定一個介於0~1的數當seed
以下是某個call random副程式的例子(取50個亂數)
program random_number
integer a(50),I
seed=0.159
do 10,I=1,50
call random(a(I),seed)
10 continue
write(*,*) a
stop
end
subroutine random(n,seed)
implicit real (a-h,o-z)
pi=3.1416
x=(seed+pi)**5
xint=int(x)
xi=x-xint
seed=xi
n=int(seed*10)
return
stop
end
若有同學不懂 請找我 謝謝
化工系309室 洪仕馨
--
※ 發信站: 批踢踢實業坊(ptt.csie.ntu.edu.tw)
◆ From: 140.112.22.37
討論串 (同標題文章)