常买彩票的人都知道,当自己懒得想号码的时候,有一种选择叫做“机选”,其实机选就是在一定范围内随机生成一组不重复的数字。今天介绍这段JavaScript脚本程序可以帮助您挑选彩票号码,首先选择要挑选的号码数量,然后选择一个数字范围,程序会生成一组你想要的号码,试试吧! 当您下次再买彩票不知道买什么号码的时候,或许可以用上这个选号器,至少不用担心被忽悠,毕竟这段代码是开源的。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>彩票号码随机生成选择器</title> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function numbers() { var nummenu = document.lotto.numbercount; var numbercount = nummenu.options[nummenu.selectedIndex].value*1; var maxnumbers = document.lotto.maxnum.value*1; if (numbercount > maxnumbers) { alert("Be sure to select a max lottery number value!"); } else { var ok = 1; r = new Array (numbercount); for (var i = 1; i <= numbercount; i++) { r[i] = Math.round(Math.random() * (maxnumbers-1))+1; } for (var i = numbercount; i >= 1; i--) { for (var j = numbercount; j >= 1; j--) { if ((i != j) && (r[i] == r[j])) ok = 0; } } if (ok) { var output = ""; for (var k = 1; k <= numbercount; k++) { output += "数字 " + k + " = " + r[k] + "\n"; } document.lotto.results.value = output; } else numbers(); } } // End --> </script> </head> <body> <center> <form name="lotto"> <table width=100% border=0> <tr> <td align=center>选择 <select name="numbercount"> <option value="1">1 <option value="2">2 <option value="3">3 <option value="4">4 <option value="5">5 <option value="6" selected>6 <option value="7">7 <option value="8">8 <option value="9">9 <option value="10">10 </select> 个号码<br> 范围:从1到 <input type=text name=maxnum value="49" size=2 maxlength=2><br> <input type=button value="选择号码" onClick="numbers()"> <p> <textarea name="results" rows=11 cols=15>