作者realll (IMOK)
看板Visual_Basic
标题Re: [VBA ] 如何用VBA产生1-81之间的乱数?
时间Tue Nov 29 22:26:15 2005
我研究出来了!!!
分享给大家~!
Sub imok() 'Private
Dim a, i, j, z, x, y As Integer
Dim AD As Double
Dim renn(1, 90)
Dim ren(1, 90) '伫列长度
Set ws1 = Worksheets("Sheet1")
Set ws2 = Worksheets("Sheet2")
Set ws3 = Worksheets("Sheet3")
Dim temp As Double
Dim check As Integer
Randomize Timer
Dim N(80)
For i = 0 To 79 '乱数序列中不会有相同的数字
r = 1
Do Until r <> 1 'r = 1 表示n(i)的乱数有重覆
N(i) = Int(80 * Rnd) + 1
r = 0
For j = 0 To i - 1
If N(i) = N(j) Then r = 1
Next
Loop
ws1.Cells(i + 1, 4) = N(i)
Next
ws1.Cells(1, 4) = 81
End Sub
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.175.196.240