![]() |
PCDVD數位科技討論區
(https://www.pcdvd.com.tw/index.php)
- 七嘴八舌異言堂
(https://www.pcdvd.com.tw/forumdisplay.php?f=12)
- - 能看出這個簡單程式有什麼問題的人絕對是個高手
(https://www.pcdvd.com.tw/showthread.php?t=816594)
|
|---|
引用:
咦?搞不好問題就出在這邊喔~~ 害大家在機率上瞎鬧了半天... XD |
引用:
他前面有用Randomize 去種RND的Seed, 沒帶參數的話就是用目前時間去當Seed |
經過我用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) |
引用:
原來如此 感謝告知 自己寫過都沒想到這方法 |
如果以很嚴謹的討論來說,這個程式的危機有兩個
第一個在於時間上的危機 為了採用類似bubble sort去除選取數的方式 一開始設定了ball(i)的39次for迴圈是很花時間的 如果採用重複性確認的方式 可由機率算出,不見得會花比較多迴圈 第二,機率上的危機 Rnd是否為真亂數? 通常是亂數產生理論上一定有某些數字的機率比較高 時間種子是否真能無規律?當同樣的程式跑個一千萬遍時,取時間的種子有可能有規律 可以採用類似quick sort 避免worst case的危機 把ball(i)採用亂數排列 這樣子規律幾乎可以被排除 |
樓主呢?這個程式的問題到底是啥?
|
答案到底是啥呢 關注很久了耶 :confused:
|
引用:
多看一些樓主的文就知道他是什麼貨色了 :think: |
抽出34~39的機率比較高,而且有可能重複
|
6個數字都猜中的機率是 1/39C6=1/3262623
不知道對不對 :ase |
| 所有的時間均為GMT +8。 現在的時間是12:45 PM. |
vBulletin Version 3.0.1
powered_by_vbulletin 2025。