lang • rnd

Rnd

Float = Rnd ( [ Min [ , Max ] ] )

Compute a pseudo-random floating point number.

  • If no parameters is specified, returns a pseudo-random number in the interval [ 0 , 1 [.

  • If only one parameter is specified, returns a pseudo-random in the interval [ 0 , Min [.

  • If both parameters are specified, returns a pseudo-random in the interval [ Min , Max [.

The higher born of the interval is never returned. This is why the interval is ended by a right square bracket!

The algorithm producing the pseudo-random numbers is a twisted generalized feedback shift register.

Examples

' Between 0 and 1
Print Rnd
0.019539254718
' Between 0 and 2
Print Rnd(2)
0.040205506608
' Between Pi and Pi*2
Print Rnd(Pi, Pi(2))
3.204108046818
Public Sub Main()

  Dim Dice As Integer

  Randomize

  Dice = Int(Rnd(1, 7))

  ' Throws the dice between 1 and 6
  Print "You threw a " & dice

End

See also