日期:2010-07-20 浏览次数:21039 次
写这个文章绝对是偶然的偶然的机会,前年等一回的 元旦节,和 老婆上街 溜达,猛然想起买上一张福利彩票,结果屁都没有中上,开春第一天,就写了个预测彩票中奖的程序,这其中的一个很关键的算法就是如何生成一个不重复的随即数字,大家看完这个程序以后如果中奖,千万不要忘记豆腐了呀:)
Sub CalCaPiao()
Dim strCaiPiaoNoArr() As String
Dim strSQL As String
Dim strCaiPiaoNo As String
strCaiPiaoNo = "01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33"
Dim StrTempArr(7) As String
Dim strZhongJiangArr(7) As String
strCaiPiaoNoArr = Split(strCaiPiaoNo, ",")
Dim intRand As Integer
Dim i As Integer
Dim j As Integer
i = 0
Dim find As Boolean
Do While True
find = False
Randomize
intRand = Int((33 * Rnd) + 1)
For j = 0 To i - 1
If StrTempArr(j) = CStr(intRand) Then
find = True
End If
Next
If Not find Then
StrTempArr(j) = CStr(intRand)
strZhongJiangArr(i) = CStr(intRand)
'Text1(i) = strZhongJiangArr(i)
i = i + 1
If i = 7 Then
Exit Do
End If
End If
Loop
End Sub
呵呵,过几天,我把这个程序搞成组件,放到我的站点上 大家一起来玩玩,呵呵!