看板 Rubiks 關於我們 聯絡資訊
※ 引述《terrorlone (快要得憂鬱症的星君)》之銘言: : ※ 引述《ten7728 (今古庸龍)》之銘言: : : x=Math.round(Math.random()*6) : Math.random() 產生出來的是範圍落在 [0,1) 之間的浮點亂數, : 因此如果你將它乘以 6 再用 round(四捨五入)的話, : 其實機率分佈會是 (0,1,2,3,4,5,6) 分別以 (1,2,2,2,2,2,1) 的比例出現, : 換句話說 6 出現的機率只有 1~5 的一半,我相信這不是你要的。 : 因此你應該把這行改成: : x=Math.ceil(Math.random()*6); : 這麼一來就會是均勻的 1~6 之亂數。 隨機出現的比例確實沒有平均..... 謝謝糾正^_^ 修改後如下: <script language="javascript"> function one() { x=Math.ceil(Math.random()*6) if(x==1){document.write("R")} if(x==2){document.write("L")} if(x==3){document.write("U")} if(x==4){document.write("D")} if(x==5){document.write("F")} if(x==6){document.write("B")} } function two() { y=Math.ceil(Math.random()*3) if(y==1){document.write(" ")} if(y==2){document.write("' ")} if(y==3){document.write("2 ")} } for(z=0;z<26;z=z+1){ one()+two() } </script> 目前仍然無法解決會連續出現的BUG 就是.... 如果第一步是R,第二步有六分之一的機率仍然出現R 如果第一步是L,第二步有六分之一的機率仍然出現L 以此類推..... -- 今古庸龍魔方網http://dragoncube.org/ 今古庸龍魔方論壇http://dragoncube.org/forum/ 台灣香港澳門魔術方塊俱樂部 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 125.230.151.149 ※ 編輯: ten7728 來自: 125.230.151.149 (03/05 19:21)
adamsun0306:我的C++爬過嗎? 03/05 21:27
ten7728:在哪裡?很想知道大大寫的C++程式~~ 03/05 22:19