Randomize (statement)


Randomize [seed]


Initializes the random number generator with a new seed.


If seed is not specified, then the current value of the system clock is used.


This example sets the randomize seed then generates six random numbers between 1 and 54 for the lottery.

Const crlf = Chr$(13) + Chr$(10)

Sub Main()
  Dim a%(5)
  Randomize 'This sets the random seed.
         'Omitting this line will cause the random numbers to be
         'identical each time the sample is run.

  For x = 0 To 5
    temp = Rnd(1) * 54 + 1

    'Elimininate duplicate numbers.
    For y = 0 To 5
      If a(y) = temp Then found = true

    If found = false Then a(x) = temp Else  x = x - 1

    found = false

  ArraySort a 
  msg1 = ""
  For x = 0 To 5
    msg1 = msg1 & a(x) & crlf
  Next x 

  MsgBox "Today's winning lottery numbers are: " & crlf & crlf & msg1
End Sub

See Also

Random (function); Rnd (function).

More information