用JavaScript寫了一個Scrambler - 魔術方塊
By Ida
at 2009-03-05T19:20
at 2009-03-05T19:20
Table of Contents
※ 引述《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/
台灣香港澳門魔術方塊俱樂部
--
: ※ 引述《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/
台灣香港澳門魔術方塊俱樂部
--
Tags:
魔術方塊
All Comments
By Eden
at 2009-03-08T19:32
at 2009-03-08T19:32
By Rosalind
at 2009-03-11T15:25
at 2009-03-11T15:25
Related Posts
5x5x5 leejaypiqq 128.64
By Lydia
at 2009-03-05T07:51
at 2009-03-05T07:51
有沒有人有偽官5心得?
By Kristin
at 2009-03-05T01:36
at 2009-03-05T01:36
新手想問哪種方塊比較安靜^^
By Andy
at 2009-03-05T01:21
at 2009-03-05T01:21
Japan─秋元正行─2x2x2電視報導
By Erin
at 2009-03-05T01:05
at 2009-03-05T01:05
新竹市第二屆魔術方塊大賽 意願調查
By Carolina Franco
at 2009-03-05T00:17
at 2009-03-05T00:17