[转-来自啊泰]彩票随机生成器原型 [http://www.cnblogs.com/babyt/archive/2005/04/08/134092.html]

以后买彩票的时候可以用用,哈哈
不过还存在不少细节问题,比如说逻辑控制不严密等等
这个等谁用的时候自己去改改吧

<%
'*************************************************************************
'
**文件名称:Lottery.asp
'
**功能描述:彩票随机生成器模型
'
            本程序为程序原型,未进行校验和保护及美化
'
            程序默认为你按照正常规则操作
'
**全局变量:
'
**调用模块:
'
**作    者:Babyt(阿泰)
'
**日    期:2005-04-08
'
**修 改 人:
'
**日    期:
'
**版    本:V1.0.0
'
版权:原创
'
授权:免费共享
'
Url: http://www.cnblogs.com/babyt
'
*************************************************************************
Randomize
Dim iStep
iStep
=Request("step")
If iStep="" Then iStep="0"
Select Case iStep
    
'初始界面
    Case "0"
    '生成后的界面
        %>
        
<Form method=post>
            彩票机生成器
<BR>
            本程序为模型,未进行校验和保护
<BR>            
            彩球总数 
<input type="input" size=10 maxlength=2 value="35" name="a1"> 
            开奖球数 
<input type="input" size=10 maxlength=1 value="7" name="a2"> 
            
<input type="hidden" name="step" value="1">
            
<input type="submit" value="生成">
        
</Form>
        
<%
    
Case "1"
        '选取后的界面(可以回退到前一界面重新选取)    
        Dim iAll,iSelect,i
        iAll
=Request("a1")
        iSelect
=Request("a2")
        %
>
        
<font color=red><%=iAll%></font><font color=blue><%=iSelect%></font><BR>
        
<Form method=post>
        本程序为模型,未进行校验和保护
<BR>
        如果必选和必不选中选中了同样的数字,则默认为选中,不进行提示
<BR>
        注意,您选择的不选条件越多,生成的速度会越慢
<BR>
        
<input type="submit" value="开始随机生成">
        
<HR size=1>
        必选:
<BR>
        
<%
        
For i=1 To iAll
            %
>
            
<input type="checkbox" name=s1 value="<%=i%>"><%=i%>&nbsp;&nbsp;
            
<%
            
If i Mod 10 =0 Then Response.Write "<BR>"
        Next
        %
>
        
<HR>
        必不选:
<BR>
        
<%
        
For i=1 To iAll
            %
>
            
<input type="checkbox" name=s2 value="<%=i%>"><%=i%>&nbsp;&nbsp;
            
<%
            
If i Mod 10 =0  Then Response.Write "<BR>"
        Next
        %
>
        
<input type="hidden" name="step" value="2">
        
<input type="hidden" name="a1" value="<%=iAll%>">
        
<input type="hidden" name="a2" value="<%=iSelect%>">
        
</Form>
        
<%
    
Case "2"
        '使用字串而不使用数组提高对比速度
        Dim sS1,sS2,aS1,aS2,iS1,iCount,xrnd
        iAll
=Request("a1")
        iSelect
=Request("a2")
        
        
'替换里面可能存在的空格
        sS1=Replace(Request.Form("s1")," ","")
        sS2
=Replace(Request.Form("s2")," ","")
        
        Response.
Write iAll & "" & iSelect & "<BR>"
        Response.Write "必选:" & sS1 & "<BR>"
        Response.Write "必不选:" & sS2 & "<BR>"
        
        sS2
= "," & sS2 & ","
        '判断必选的个数
        'iS1为需要选取的个数
        If sS1="" Then
            iS1
=iSelect
        
Else
            aS1
=Split(sS1,",")    
            
'重新组织sS1                        
            sS1= "," & sS1 & ","            
            iS1
=iSelect - Ubound(aS1)-1    
            
'Response.Write "dddd" & iS1
        End If
        
'开始生成
        iCount=0
        
Call GenNumber
        
'Response.Write "选取结果:<font color=red>" & Mid(sS1,2,Len(sS1)-2) & "</font><BR>"
        
        
'把结果进行排序
        sS1=Mid(sS1,2,Len(sS1)-2)
        
Dim sReturn,arrS
        arrS
=Split(sS1,",")
        
Call SortIt()
        
For i=0 To UBound(arrS)
            sReturn 
= sReturn & arrS(i) & ","
        Next
        Response.
Write Left(sReturn,Len(sReturn)-1)
    
End Select

'数字生成
Function GenNumber()
    
Randomize
    xrnd
=Cint(RND*(iAll+1))
    
If xRnd>=1 And xRnd<=iAll Then
        
'如果不在必选的范围内,则继续
        If Instr(1,sS1, "," & xRnd & ",",1)<=0 Then
            
'如果不在必不选的范围内,则继续
            If Instr(1,sS2, "," & xRnd & ",",1)<=0 Then
                
'组合成已选字串
                sS1=sS1 & xRnd & ","
                iCount=iCount+1
                
If iCount>=iS1 Then                                    
                    
Exit Function
                
End If
            
End If
        
End If                
    
End If
    
'递归
    GenNumber
End Function


'数组排序
Function SortIt()
    
Dim i,s0,iCount,j
    iCount
=0
    
For i=0 To UBound(arrS)
        
If i+1<=UBound(arrS) Then
            
If CInt(arrS(i))>Cint(arrS(i+1)) Then
                s0
=arrS(i)
                arrS(i)
=arrS(i+1)
                arrS(i
+1)=s0
                iCount
=iCount+1
            
End If
        
End If
    
Next
    
If iCount=0 Then Exit Function
    
'递归
    SortIt()
End Function

%
> 
 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值