喜欢买彩票的朋友可以参考下啊呵呵
<!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>
<title>周末无聊,给老婆写个双色球的生成</title>
<style>
.rednum{
position:absolute;
left:30px;
top:25px;
font-size:25px;
color:red;
font-family:Georgia;
font-weight:bold;
}
.bluenum{
position:absolute;
left:250px;
top:25px;
font-size:28px;
color:blue;
font-family:Georgia;
font-weight:bold;
}
.showresult{
position:absolute;
left:300px;
top:400px;
font-size:25px;
width:500px;
color:black;
font-family:Georgia;
font-weight:bold;
}
.showNumCount{
position:absolute;
left:300px;
top:200px;
}
.showall{
position:absolute;
left:0px;
top:50px;
z-index:40;
font-size:25px;
width:300px;
text-align:left;
color:green;
font-family:Georgia;
font-weight:bold;
}
.showInfo{
position:absolute;
right:0px;
top:50px;
z-index:40;
font-size:25px;
width:300px;
text-align:left;
color:black;
font-family:Georgia;
font-weight:bold;
}
</style>
<title></title>
<script>
/**
* 无聊,模拟一下双色球的生成
* 家人以后买彩票 就可以拿这个参考了 ^_^
* @author zjq june 6 2010
*/
var sec =100;//生成间隔
var saveArray = new Array();//保存数值
function CreateColorTicket(){
document.getElementById('showNumCount').innerHTML="";
var count =document.getElementById('textinput').value-'0';
if(!/^[0-9]*$/i.test(count)){alert('Invade input!');return;}
if(count==0){alert('the num input must > 0');return;}
if(count==1){
var result = cct(1);
document.getElementById('showresult').innerHTML="本次推荐(by 迁)
:"+result;
}else{
//用列表显示 数值
var ul =document.getElementById('showall');
ul.innerHTML="";
if(count<20){
for(var i = 1;i<=count;i++){
var li = document.createElement("li");
var result = cct(2);
saveArray.push(result);
li.innerHTML=result;
ul.appendChild(li);
}
getNumCount();
}else{
saveArray = new Array();
for(var i = 1;i<=20;i++){
var li = document.createElement("li");
ul.appendChild(li);
}
for(var i = 1;i<=count;i++){
var result = cct(2);
saveArray.push(result);
}
setTimeout("initul(0)",100);
}
}
}
var setint;
var over = true;
function initul(st){
var ulNodes =document.getElementById('showall').childNodes;
var ct = 0;
for(var j=0,k=st;j<ulNodes.length;j++,ct++,k++){
//alert(saveArray[k]);
if(saveArray[k]==undefined||saveArray[k]==null){
getNumCount();
clearInterval(setint);over=false;
}else{
ulNodes[j].innerHTML = saveArray[k];
}
//if(ct>20){st++;break;}
}
st++;
if(over){setint = setTimeout("initul("+st+")",sec);}
}
//随即一次
function cct(type) {
var redArray = new Array(33);
//红球 初始值 1-33
for (var i = 0; i < redArray.length; i++) {
redArray[i] = i + 1;
}
var ticks = "";
var loop = 6;
var red_count = [1,2,3,4,5,6];
var rc = 0;
var blue_count = 0;
while (loop > 0) {
//随即抽取红球数组下标
var redBallIndex = parseInt(Math.random()
*redArray.length);
var redBall = redArray[redBallIndex];
red_count[rc++] = redBall;
//便于查看
if (loop == 1) {
ticks += redBall;
} else {
ticks += redBall + ",";
}
//去除已经产生的红球号码,赋给新数组
var m = new Array();
for (var i = 0, k = 0; i < redArray.length; i++,
k++) {
if (redArray[i] != redBall) {
m[k] = redArray[i];//不同则加入
} else {
k--;//相同则取消数组m的下标+1
}
}
redArray = m;//去除已选号的新数组
loop--;
}
//蓝色号码
var blueBall = parseInt(Math.random()*16 + 1);
//document.getElementById('line').style.display='';
if(type==1){
document.getElementById
('showred').innerHTML=ticks;
document.getElementById
('showblue').innerHTML=blueBall;
}
return ticks+"|"+blueBall;
}
//统计各数字出现的频率
function getNumCount(){
var red = new Array(33);
var blue =new Array(16);
for(var i =0;i<33;i++){
red[i]=0;
if(i<16){blue[i]=0;}
}
//alert(saveArray.length);
for(var i =0;i<saveArray.length;i++){
var rbs = saveArray[i];
var rb = rbs.split("|");
var r = rb[0].split(",");
for(var j= 0;j<r.length;j++){
red[r[j]-1]+=1;
}
blue[rb[1]-1]+=1;
}
var redStr ="",blueStr="";
var ct=0,ct2=0;
for(var e in red){
redStr+=(parseInt(e)+1)+":<font color='red'>"+red[e]
+"</font> ";
ct++;
if(ct==8){redStr+="<br>";ct=0;}
}
for(var e in blue){
blueStr+=(parseInt(e)+1)+":<font color='red'>"+blue[e]
+"</font> ";
ct2++;
if(ct2==8){blueStr+="<br>";ct2=0;}
}
document.getElementById('showNumCount').innerHTML="红球统计:
<br>"+redStr+"<p>蓝球统计:<br>"+blueStr;
saveArray = new Array();
var maxredstr="";maxbluestr="";
//统计本次出现频率最高的红,蓝球
//如果次数相同,则取数字小的
var rmax = 0,bmax=0;
var rindex =0,bindex=0;
for(var j =1;j<=6;j++){
for(var e in red){
if(red[e]>rmax){
rmax =red[e];rindex= e;
}
}
maxredstr+=parseInt(rindex)+1+",";
red[rindex]=0;//清空最高频率的数,查找下一个
rmax=0;rindex =0;
}
for(var e in blue){
if(blue[e]>bmax){
bmax =blue[e];bindex= e;
}
}
maxredstr = maxredstr.substring(0,maxredstr.lastIndexOf(","));
maxredstr+="|"+(parseInt(bindex)+1);
document.getElementById('showresult').innerHTML="本次推荐(by 迁)
:"+maxredstr;
}
</script>
</head>
<body>
<div>
彩票生成区域:
<div id="showred" class="rednum"></div>
<div id="showblue" class="bluenum"></div>
</div>
<center>
<div id="showMsg" style="color:pink"></div>
<script>
var msg="欢 迎 使 用 本 彩 票 程 序,祝 你 中 大 奖 ^_^";
var seq=0;
var obj = document.getElementById('showMsg');
//从左到右,逐渐显示
function Scroll() {
len = msg.length;
obj.innerHTML = msg.substring(0, seq+1);
seq++;
if ( seq >= len ) {
seq = 0;
window.setTimeout("Scroll2();", 100);
}
else{
window.setTimeout("Scroll();", 100 );
}
}
function Scroll2() {
len = msg.length;
obj.innerHTML=msg.substring(seq, len);
seq++;
if ( seq >= len ) {
seq = 0; window.setTimeout("Scroll();", 200);
}else{
window.setTimeout("Scroll2();", 100);
}
}
Scroll();
</script>
<div class="showInfo"> 时间仓促,没有具体调试,如有bug,请按<font
color="red">F5</font> 刷新页面即可^_^^_^^_^</div>
<input type="button" value="机选一注" onclick ="cct
(1)"/> 或:</br>
输入要生成的注数:<input type="text" id="textinput" size="5" value=""/>
<input type="button" value="试试手气" onclick ="CreateColorTicket
();"/></br>
调整生成速度:
<input type="button" value="速度+" onclick ="if(sec>10)sec-=50;"/>
<input type="button" value="速度-" onclick ="sec+=50"/>
<div id = "showNumCount" class="showNumCount"></div>
<div id="showresult" class="showresult"></div>
<ul id="showall" class="showall">
</ul>
</center>
</body>
</html>