用JavaScript寫了一個Scrambler - 魔術方塊
By Caitlin
at 2009-03-04T10:36
at 2009-03-04T10:36
Table of Contents
最近在學習JavaScript,今天利用JavaScript寫了一個Scrambler的簡單簡單簡單程式,
,隨機出現亂數原始碼如下:
<script language="javascript">
function one()
{
x=Math.round(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()
{
a=Math.round(Math.random()*3)
if(a==1){document.write("")}
if(a==2){document.write("'")}
if(a==3){document.write("2")}
}
for(z=0;z<26;z=z+1){
one()+two()
}
</script>
設計原理:利用Javascript的亂數函數隨機獲得1~6的數字以及1~3的數字,1~6每一個
數字對應到(RLUDBF),1~3對應到(無、'、2),最後執行25次,得到25個亂數。
附註:
如果你有看出來,會發現本程式並沒有達到「真正的隨機」......而且有BUG的問題...
--
今古庸龍魔方網http://dragoncube.org/
今古庸龍魔方論壇http://dragoncube.org/forum/
台灣香港澳門魔術方塊俱樂部
--
,隨機出現亂數原始碼如下:
<script language="javascript">
function one()
{
x=Math.round(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()
{
a=Math.round(Math.random()*3)
if(a==1){document.write("")}
if(a==2){document.write("'")}
if(a==3){document.write("2")}
}
for(z=0;z<26;z=z+1){
one()+two()
}
</script>
設計原理:利用Javascript的亂數函數隨機獲得1~6的數字以及1~3的數字,1~6每一個
數字對應到(RLUDBF),1~3對應到(無、'、2),最後執行25次,得到25個亂數。
附註:
如果你有看出來,會發現本程式並沒有達到「真正的隨機」......而且有BUG的問題...
--
今古庸龍魔方網http://dragoncube.org/
今古庸龍魔方論壇http://dragoncube.org/forum/
台灣香港澳門魔術方塊俱樂部
--
Tags:
魔術方塊
All Comments
By Leila
at 2009-03-05T10:08
at 2009-03-05T10:08
By Ula
at 2009-03-05T14:42
at 2009-03-05T14:42
By Catherine
at 2009-03-06T02:23
at 2009-03-06T02:23
By Edith
at 2009-03-06T07:49
at 2009-03-06T07:49
By Aaliyah
at 2009-03-06T17:30
at 2009-03-06T17:30
By Isla
at 2009-03-09T16:49
at 2009-03-09T16:49
Related Posts
im956vu86
By Yuri
at 2009-03-03T23:11
at 2009-03-03T23:11
im956vu86
By Ingrid
at 2009-03-03T23:01
at 2009-03-03T23:01
一個高階組中心的小小構思
By Mia
at 2009-03-03T22:43
at 2009-03-03T22:43
im956vu86
By Audriana
at 2009-03-03T22:33
at 2009-03-03T22:33
im956vu86
By Sandy
at 2009-03-03T22:16
at 2009-03-03T22:16