I'm sure one of the expert residents (nudge at comatose) can explain a lot more....
No Pressure There! :eek:
Here is a small breakdown of the way it works. When you call the rnd function, it keeps the seed value in memory. Calling rnd again will give you the same number. When you call randomize, it resets this stored value. See, computers generate Psuedo-Random numbers. Think of a very long list of numbers, and the computer always returns the values in the same order, but it doesn't always
Start at the same place in the list.
Waltp is right, in that you only actually need to reset the seed once. Form_load is a nice place for that, but it won't cause any problems re-seeding the psuedo-number generator. It is, however, not very good programming style to re-seed the number generator.
I call randomize with timer as the seed (
randomize timer), which just make it a little more psuedo-random. Should you want to know the last random number called, pass 0 to rnd, and it will tell you the last random number generated, such as
lastrand = rnd(0). I have no clue why you would want to do that (unless it's to make sure the new number is not the same), but you can.
The rnd function returns values smaller than 1, but greater than or equal to 0, which sort of sucks. You can fix this, though with a little function:
Public Function Rand(LowNum as long, HighNum as long) as long
xRand = int((HighNum - LowNum + 1) * Rand) + Low
end function