|
|
Title | Make a random choice using the PickOne function |
Keywords | pick one, PickOne, random |
Categories | Algorithms, Tips and Tricks |
|
|
The PickOne function lets you quickly pick an item from a fixed list as in:
lblResult.Caption = PickOne("Program", "Debug", "Email", "Write")
|
|
' Return a randomly selected argument.
Private Function PickOne(ParamArray choices() As Variant) _
As Variant
Dim min_i As Integer
Dim max_i As Integer
Dim rnd_i As Integer
min_i = LBound(choices)
max_i = UBound(choices)
rnd_i = Int((max_i - min_i + 1) * Rnd + min_i)
PickOne = choices(rnd_i)
End Function
|
|
|
|
|
|