彩票程序(要全部是html或htm的)

彩票程序(要全部是html或htm的),第1张

<html>

<script>

function $(obj){return document.getElementById(obj)}

var n , _startNum , _endNum ,currIndex, numArr

function randomNum( )

{

var t= new Date()

var ms = t.getMilliseconds()

var s = t.getSeconds()

var m = t.getMinutes()

var h = t.getHours()

var luck = parseInt( $("luckNum").value,10)

var bm = parseInt( $("mm").value,10)

var bd = parseInt( $("dd").value,10)

var delayRondom = h + m + s + ms - Math.ceil( (ms/4)*3 )

var randomNum =( ms + s + luck + bm + bd ) % (_endNum + (ms%2) )

var isExist=false

for(var i=0i<numArr.length i++)

if( numArr[i] == randomNum )isExist=true

if( !$("reNum").checked )

{

if( isExist==false &&randomNum >= _startNum)

{

numArr.push( randomNum )

}

else

{

setTimeout( "randomNum()" , delayRondom )

return

}

}

var span = document.createElement("span")

span.innerHTML= "第"+ currIndex + "个号码:" + randomNum + "<br>"

$("showNum").appendChild(span)

if( currIndex <n )

{

setTimeout( "randomNum()" , delayRondom )

currIndex ++

}

}

function makeNum()

{

var strN = $("numCount").value

var strStartNum = $("startNum").value

var strEndNum = $("endNum").value

$("showNum").innerText=""

currIndex=1

numArr = new Array()

if( !isNaN( strN + strStartNum + strEndNum ) )

{

n = parseInt(strN,10)

_startNum = parseInt(strStartNum,10)

_endNum = parseInt(strEndNum,10)

if( (_endNum - _startNum)>n )

randomNum()

else alert("设置错误!范围必须大于生成个数!")

}

else alert("请设置正确的范围和生成个数!")

}

function initSelect(sel, _begin, _end)

{

for(var i=_begini<=_endi++)

{

sel.options.add( new Option( i , i) )

}

}

window.onload=function( )

{

initSelect( $("luckNum") ,0,100)

initSelect( $("mm") ,1,12)

initSelect( $("dd") ,1,31)

}

</script>

<body>

<h1>彩码生成程序</h1>

<div id=showNum ></div>

<br>

<input type=checkbox id=reNum >重复码(打钩是可重复码)

<br>

你需要:<input id=numCount value="7" >个码

<br>

范围从:<input id="startNum" value="0" >至

<input id="endNum" value="36" >小于1000

<br>

请输入你的生日:<select id=mm ></select>月  

<select id=dd ></select>日

<br>

请输入你的幸运数字:<select id=luckNum ></select>

<br>

<input type=button value ="生成彩票码" onclick="makeNum()">

</body>

</html>

public class RandomDemo {

public static void main(String[] args) {

LotteryTicket lt = new LotteryTicket()

int red[] = lt.getRed()

System.out.print("随机生成的红球为:")

for(int i=0i<6i++){

System.out.print(" "+red[i])

}

System.out.print("\t蓝球为:"+lt.getBlue())

}

}

class LotteryTicket{彩票生成类

private int[] red = new int[6]

public int[] getRed(){//返回红球

int i =0

for(i<6i++){

red[i] = (int)(Math.random()*33) +1

for(int j=0j<ij++){//保证了重复,我个从认为这个彩票好像不能重复吧

if(red[i]==red[j]){

red[i] = (int)(Math.random()*33) +1

j=0

}

}

}

return red

}

public int getBlue(){//返回蓝球

return (int)(Math.random()*16) +1

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12056330.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存