Rnd (function)

Syntax

Rnd[(number)]

Description

Returns a random Single number between 0 and 1.

Comments

If number is omitted, the next random number is returned. Otherwise, the number parameter has the following meaning:

 

If

Then

 

Number < 0

Always returns the same number.

 

Number = 0

Returns the last number generated.

 

Number > 0

Returns the next random number.

Example

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 

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

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

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

    found = false
  Next  

  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

Randomize (statement); Random (function)

More information

R