The statement Rnd() returns a value such that it is greater than or equal to zero and less than 1 <= R<1.

The table below shows the transformation of a random number to a random value from 1 to 6:

Rnd() Rnd() * 6 Int(Rnd()*6) Int(Rnd()*6)+1
0.000 0.000 0 1
0.399 2.394 2 3
0.575 3.450 3 4
0.776 4.656 4 5
0.999 5.994 5 6
0 <= num < 1 0.0 <= num < 6.0 0 <= num< 6 1 <= num <= 6

A general rule is to multiply by the number of values in the range and then add the lowest value in the range.
This Flash movie allows you to enter the first and last values and see the Visual Basic statement to compute the random numbers.
The Go button will generate random numbers in the specified range.


INDEX, Built in Functions and Constants, Functions, Random Numbers, How Random Numbers Work, RGB Colors, Random Colors
Next lesson: Visual Basic Calculations

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

How Random Numbers Work