我想问一下怎么实现抽奖的中心算法

nfenghklibra 2004-04-06 11:25:31
小弟在做一个抽奖程序,由N条记录滚动,可以是随机的也可以是顺序的.怎么样才能作到抽奖的公平.
...全文
18 点赞 收藏 2
写回复
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
sportdog 2004-07-12
<%@ Language=VBScript %>
<%
on error resume next
Set InfoDB = Server.CreateObject("ADODB.Connection")
InfoDB.Open "provider=sqloledb;server=dbserver;uid=infouser;pwd=infouser;database=infodb"
sql = "select rtrim(fcst_name)+':'+fcp_series as card from t_customer a,T_CUSTOMER_PURCHASE b where a.fcst_id=b.fcp_cst_id"
set rs = infodb.Execute(sql)
if err.number<>0 then
Response.Write "提取数据失败"
Response.End
end if
strinfo=""
while not rs.eof
strinfo=strinfo&trim(rs("card"))&","
rs.movenext
wend
%>

<HTML><HEAD><TITLE>抽奖</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 5.50.4807.2300" name=GENERATOR>
<style>
.input_text{ Height:27;font-size: 20;font-weight: bold;font-family: 黑体;BORDER-RIGHT: silver 1px solid; BORDER-TOP: silver 1px solid; OVERFLOW: hidden; BORDER-LEFT: silver 1px solid; BORDER-BOTTOM: silver 1px solid; FONT-FAMILY: 宋体; BACKGROUND-COLOR:#ccffcc;color:#006600}
.input_text2{ Height:27;font-size: 20;font-weight: bold;font-family: 黑体;BORDER-RIGHT: silver 1px solid; BORDER-TOP: silver 1px solid; OVERFLOW: hidden; BORDER-LEFT: silver 1px solid; BORDER-BOTTOM: silver 1px solid; FONT-FAMILY: 宋体; BACKGROUND-COLOR:#000000;color:#33ff66}
</style>
</HEAD>
<BODY>
<INPUT size=22 name=show1 class="input_text2" readonly style="WIDTH: 315px; HEIGHT: 27px">
<br><br><BUTTON id=startb onclick='timer = setInterval("giveone()",27);this.disabled=true;endb.disabled=false;'>开始</BUTTON>
   <BUTTON id=endb onclick='StopGo();' disabled>停止</BUTTON>
<SCRIPT language=JavaScript>
var timer;
var strtmp ;
var arr;
var allstr;
allstr="<%=strinfo%>";
//allstr = "苏A AA021,苏B U8201,苏A W3351,";//苏A X2455,苏A AE666,苏A AF888,苏A AG443,苏A Y4545,苏A X3221,
strtmp = allstr.split(",");
function giveone()
{
var rndNum1 = parseInt(Math.random() * strtmp.length+1);
var i;
var cfflag;
arr = Go1.innerText.split(",");
if(arr.length>=strtmp.length)
{
document.all.show1.value="";
clearInterval(timer);
alert("已经抽出的等于总数");
startb.disabled=false;
endb.disabled=true;
return false;
}
else
{
if(strtmp[rndNum1-1].length!=0)
{
for(i=0;i<arr.length;i++)
{
if(arr[i]!=strtmp[rndNum1-1])
{
cfflag=0;
}
else
{
return false;
}
}
}
}
if(cfflag==0)
{
document.all.show1.value = " "+strtmp[rndNum1-1];
}
else
{
return false;
}
}

function StopGo()
{
var str;
str=Go1.innerText;
if(str.indexOf(document.all.show1.value)==-1)
{
clearInterval(timer);
Go1.innerText+=document.all.show1.value+",";
if(arr.length>=strtmp.length)
{
document.all.show1.value="";
clearInterval(timer);
alert("已经抽出的等于总数");
startb.disabled=true;
endb.disabled=true;
return false;
}
else
{
//setInterval("startb.click()",1000);
//setInterval("givetwo()",1000);
}
startb.disabled=false;
endb.disabled=true;
}
else
{
startb.disabled=true;
endb.disabled=false;
}

}

function givetwo() {
clearInterval(timer);
Go1.innerText+=document.all.show1.value+",";
startb.disabled=false;
endb.disabled=true;
return false;
}
</SCRIPT>
<TABLE>
<TR>
<TD id=Go0 height=27></TD></TR>
<TR>
<TR>
<TD id=Go1></TD></TR>
<TR>
<TD id=Go2></TD></TR>
<TR>
<TD id=Go3></TD></TR>
<TR>
<TD id=Go4></TD></TR></TABLE>
</BODY></HTML>
回复
mustapha 2004-04-07
要做到绝对公平,就要抽出的记录是随机的
用 select top 10 * from table order by newID()
来实现随机取记录
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告