您的位置:首页 > 其它

产生不重复随机数

2010-12-19 12:16 218 查看
Option Explicit
Option Base 1
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Const Nums = 10
Private Sub Command1_Click()
Dim t As Long
Dim Num(Nums) As Long
Dim i, n As Long
Dim s As String
t = timeGetTime
Randomize
For i = 1 To Nums
n = Int(Rnd * Nums) + 1
If Num(n) = 0 Then
Num(n) = n
s = s & n & ","
Else
i = i - 1 '比较妙
End If
Next i
Text1.Text = s
t = timeGetTime - t
MsgBox t
End Sub
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: