Random
Class Random
| Method Prototype | Description
|
| Sub Constructor() | initialize with an automatic seed
|
| Function Gaussian() As Double | return a Gaussian-distributed number
|
| Function InRange( minR As Integer, maxR As Integer ) As Integer | return an integer within the given range
|
| Function LessThan( range As Integer ) As Integer | return an integer greater than or equal to zero, and less than the given number
|
| Function Number() As Double | return a uniformly distributed number from 0.0 to 1.0
|
| Function Seed() As Double | get the current seed value
|
| Sub Seed(Assigns s As Double) | set the seed value
|
The Random class represents a pseudorandom number generator. Create one of these, and "draw" as many random numbers from it as you need (using the Gaussian, InRange, LessThan, or Number methods), and the collection of numbers so drawn will have good statistical properties.
Do
not create a new Random instance every time you need a random number, as in that case you would be drawing just the first number from several very similar pseudorandom sequences. That collection of numbers would have very poor stasticstical properties (i.e., would not appear very random at all).
A Random's current state is contained entirely in its Seed value. So you could save your position within the pseudorandom stream by saving the Seed value, and restoring it later. You could also initialize a new Random instance via the Seed value if you have some external source of entropy, say a nice hot cup of tea. Otherwise, you'll generally want to leave it alone, as the Constructor will automatically initialize the seed from the system clock.
Note that there is a implicit global Random instance, which is accessed via the
Rnd function.