[閒聊] 用JavaScript寫了一個Scrambler
最近在學習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/
台灣香港澳門魔術方塊俱樂部
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 125.230.151.149
推
03/04 11:30, , 1F
03/04 11:30, 1F
推
03/04 11:31, , 2F
03/04 11:31, 2F
→
03/04 11:31, , 3F
03/04 11:31, 3F
→
03/04 11:33, , 4F
03/04 11:33, 4F
推
03/04 13:51, , 5F
03/04 13:51, 5F
→
03/04 13:52, , 6F
03/04 13:52, 6F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 4 篇):
Rubiks 近期熱門文章
PTT遊戲區 即時熱門文章
-9
107