Randomize Method
The Randomize method creates a starting value for the random number generator. It does not return a value. If you do not specify a value for the number argument, then it uses the Get Seconds method to reset the random number generator.
Format
Randomize [number]
The following table describes the arguments that you can use with this method.
Argument | Description |
---|---|
number |
An integer value that is in the range of negative 32768 through 32767. |
Example
The following example uses the Randomize method and the Get Random Number method to create a random string of characters. The second For Next loop slows down processing in the first For Next loop so that the Timer method can seed the Randomize method with a new value each time the loop runs:
Sub Button_Click
Dim x As Integer, y As Integer
Dim str1 As String, str2 As String
Dim letter As String
Dim randomvalue
Dim upper, lower
Dim msgtext
upper = Asc("z")
lower = Asc("a")
newline = Chr(10)
Randomize
For x = 1 to 26
randomvalue = Int(((upper - (lower + 1)) * Rnd) + lower)
letter = Chr(randomvalue)
str1 = str1 & letter
For y = 1 to 1500
Next y
Next x
msgtext = str1
End Sub