关于随机抽奖的两个问题。

feizhou 2007-06-07 03:09:10
有很多人,有奖券,每张奖券上都有一个号,根据这个号进行抽奖。号码的格式是:

NK000000,前面是NK两个字母,后面是六个数字,实际数字不够六位的前面要补零。比如NK000639。实际的数是从1到15000左右。
要求是很简单,一个文本框,一个开始按钮,一个停止按钮。按完开始以后,在文本框里

快速滚动奖券号码,按停止后,号码停住,就是得主。

1、要求是奖号在滚动。那前面我可以就显示NK,不参与滚动,但是后面的数如何在不满六位时补零啊?

2、如果奖号不是连续的,那应该如何处理?甚至说,如果不是奖号,是一堆车牌照号,应该如何解决?(存进数据库,那要如何滚动显示?)
...全文
212 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
smartcatiboy 2007-06-07
  • 打赏
  • 举报
回复
抽奖把数据放到客户端会破产的。
jssl 2007-06-07
  • 打赏
  • 举报
回复
<%'用数组是个好办法我也担心太大了会爆哦~
'把数据库奖单号读入字串
str="000001|000002|000003|000004|000005|000006|000007|000008|000009|000010|000011|000012|000013|000014"
%>
<SCRIPT>
<!--
var str = "<%=str%>";
var tmp = str.split("|");

function CurentTime(){
var rnd = Math.round(Math.random()*(tmp.length-1));
var rnd2 = "NK" + tmp[rnd];
return(rnd2);
}
function refreshClock(){
document.all.Clock1.innerHTML = CurentTime();
}
var intervalID=0;
function plustart(){
intervalID=setInterval("refreshClock()",100);
submit1.disabled=true;
submit2.disabled=false;
}
function plustop(){
clearInterval(intervalID);
submit1.disabled=false;
submit2.disabled=true;
}
//----->
</SCRIPT>
<br>
<strong style="width:80px;"><font color="#FF0000" id="Clock1">NK000000</font></strong>
<input value="开始" type="button" id="submit1" onclick="plustart();" />
<input type="button" id="submit2" value="停止" disabled="true" onclick="plustop();"/>
smartcatiboy 2007-06-07
  • 打赏
  • 举报
回复
想了个笨办法,伪循环,数据不放在客户端,安全性比较好,但是要不停刷服务器,楼主看看行不。


客户端
<body><input id="htmNum"/><input id="htmStop" type="button" value="暂停"/></body>
<script language="vbs">
sub window_onLoad()
LoopShow
end sub

sub LoopShow()
GetNum
settimeout "loopShow",100
end sub

sub GetNum()
set oXH=createObect("microsoft.xmlhttp")
oXH.open "get","http://127.0.0.1/GetNum.asp",false
oXh.Send
if oXH.readyState=4 then
htmNum.value=oXh.responsetext
end if
set oXh=nothing
end sub

sub htmStop_onClick()
set oXH=createObect("microsoft.xmlhttp")
oXH.open "get","http://127.0.0.1/Stop.asp",false
oXh.Send
if oXH.readyState=4 then
htmNum.value=oXh.responsetext
end if
set oXh=nothing
end sub
</script>

服务器端
GetNum.asp
<%
if session("RndSeed")="" then
randomize second(now) '这里需要调整一下随机数种子,最好自己作个函数
session("RndSeed")=rnd
end if
set conn=server.createObject("adodb.connection")
set rst=server.createobject("adodb.recordset")
rst.open "select * from 奖单表",conn,3,3
if Not(rst.eof or rst.bof) then
rst.absoluteposition=rst.recordcount*rnd(session(RndSeed))+1
session("Num")=rst("奖单号")
response.write rst("奖单号")
end if
rst.close
conn.close
set rst=nothing
set conn=nothing
%>

Stop.asp
<%
if session("Num")<>"" then
response.write "中奖号码:"&session("Num")
else
response.write "无中将号"
end if
%>
李睿_Lee 2007-06-07
  • 打赏
  • 举报
回复
第一个问题好办啊。取得数字后,转成字符串,判断一下长度,不足六位,补0,不就行了吗?
第二个问题,用数组是个好办法,不过,不知道会不会爆了。。。
lihuasoft 2007-06-07
  • 打赏
  • 举报
回复
用数组啊.

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧