Using Rnd
1. Initialize the Random Number Generator: First, initialize VB6’s random number generator Randomize (typically in the Form_Load() event handler)
2. Generate a Specific Random Number: Rnd(1) gives a specific Double (large number) between 0 and 1, e.g., 0.410592664
To chose randomly among an integral number of things, say x, multiply Rnd(1) by x and truncate … the result is a random integer between 0 and x-1
- Pick among 6 things:
- Int(Rnd(1)*6) ? Rnd(1) * 6 ? 0.410592664 * 6 ? 2.463555984 ? 2
- Int(Rnd(1)*6) ? Rnd(1) * 6 ? 0.092154388 * 6 ? 0.552926328 ? 0