瀏覽單個文章
奶油銓
Basic Member
 

加入日期: Feb 2002
您的住址: 地球
文章: 20
經過我用fortran 77 改寫過後. 分析的結果也顯示這個程式沒有問題.不過我在意的不是程式本身有多精簡. 我在意的是產生的亂數到底有多亂. 而這個部分是可以測試的. 這個部分有需要者可以參閱 numerical recipe in fortran or numerical recipe in c.

底下附錄我常用的產生亂數的程式碼(從recipe中抄出來的):
----------------------------------------------------------------------
subroutine ggubs(dseed,nr,r)
double precision dseed,d2p31m,d2p31i,r(nr)
parameter(d2p31m=2147483647.d0 ,d2p31i=1.d0/2147483711.d0)

do 5 i=1,nr
dseed=dmod(16807.d0*dseed,d2p31m)
5 r(i)=dseed
do 10 i=1,nr
10 r(i)=r(i)*d2p31i
return
end
------------------------------------------------------------------------

與跑 300萬次後每個數字產生的次數(%)
total number 18000000
Times of Ball Number 1= 2.56215556
Times of Ball Number 2= 2.56126111
Times of Ball Number 3= 2.56350556
Times of Ball Number 4= 2.56408333
Times of Ball Number 5= 2.56159444
Times of Ball Number 6= 2.56643889
Times of Ball Number 7= 2.56441111
Times of Ball Number 8= 2.56470556
Times of Ball Number 9= 2.56382778
Times of Ball Number 10= 2.56243333
Times of Ball Number 11= 2.56430556
Times of Ball Number 12= 2.56394444
Times of Ball Number 13= 2.56118889
Times of Ball Number 14= 2.5694
Times of Ball Number 15= 2.56303333
Times of Ball Number 16= 2.56233889
Times of Ball Number 17= 2.56622222
Times of Ball Number 18= 2.56330556
Times of Ball Number 19= 2.56142222
Times of Ball Number 20= 2.56612222
Times of Ball Number 21= 2.56035556
Times of Ball Number 22= 2.56219444
Times of Ball Number 23= 2.56603889
Times of Ball Number 24= 2.56196111
Times of Ball Number 25= 2.56607222
Times of Ball Number 26= 2.56246667
Times of Ball Number 27= 2.56561667
Times of Ball Number 28= 2.56228333
Times of Ball Number 29= 2.56981111
Times of Ball Number 30= 2.56630556
Times of Ball Number 31= 2.56455556
Times of Ball Number 32= 2.56855
Times of Ball Number 33= 2.56631111
Times of Ball Number 34= 2.56595556
Times of Ball Number 35= 2.56980556
Times of Ball Number 36= 2.55696111
Times of Ball Number 37= 2.56235556
Times of Ball Number 38= 2.55862778
Times of Ball Number 39= 2.56807222

------------------------------------------------------------------------
(請大家不要鞭我有效位數的問題.) 又此一結果與 maria 網友的結果相同.
可以看出每個數值出現的次數趨近 2.56%. (1/39 = 0.025641026)
舊 2008-09-23, 02:11 AM #83
回應時引用此文章
奶油銓離線中