作者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