?? 隨機數.txt
字號:
無重復隨機數序列產生器
來源:http://www.planet-source-code.com
'***************************************************************
' Name: A Non-Repeating Random Number Generator
' Description:With this simple, and very fast, routine you can ge
' nerate a series of non-repeating random numbers. You can select a
' series of 10 numbers, or a series of a million...It doesn't matte
' r. Can be useful for image fades, deck shuffling, random tip of t
' he day, etc. - It even tells you how long it took to generate the
' series.
' By: Kevin Lawrence
''
' Inputs:None
'
' Returns:A popup message stating how many numbers had been mixed
' up and how long it took.
'
'Assumes:None
'
'Side Effects:The larger the series of numbers the more RAM requi
' red. Uses arrays.
'
'Code provided by Planet Source Code(tm) (http://www.PlanetSource
' Code.com) 'as is', without warranties as to performance, fitness,
' merchantability,and any other warranty (whether expressed or impl
' ied).
'***************************************************************
Private Sub Command1_Click()
'-------------------------------------------------------------
' Produces a series of X random numbers without repeating any
'-------------------------------------------------------------
'Results can be used by using array B(X)
Dim A(10000) ' Sets the maximum number to pick
Dim B(10000) ' Will be the list of new numbers (same as DIM above)
Dim Message, Message_Style, Message_Title, Response
'Set the original array
MaxNumber = 10000 ' Must equal the DIM above
For seq = 0 To MaxNumber
A(seq) = seq
Next seq
'Main Loop (mix em all up)
StartTime = Timer
Randomize (Timer)
For MainLoop = MaxNumber To 0 Step -1
ChosenNumber = Int(MainLoop * Rnd)
B(MaxNumber - MainLoop) = A(ChosenNumber)
A(ChosenNumber) = A(MainLoop)
Next MainLoop
EndTime = Timer
TotalTime = EndTime - StartTime
Message = "The sequence of " + Format(MaxNumber, "#,###,###,###") +
" numbers has been" + Chr$(10)
Message = Message + "mixed up in a total of " + Format(TotalTime,
"##.######") + " seconds!"
Message_Style = vbInformationOnly + vbInformation + vbDefaultButton2
Message_Title = "Sequence Generated"
Response = MsgBox(Message, Message_Style, Message_Title)
End Sub
以下為測試部分
'Dim i
' For i = 1 To 50
' Debug.Print B(i)
' Next i
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -