Important: The information in this document is obsolete and should not be used for new development.
RandomBits
You can use theRandomBits
function to return a sequence of pseudorandom numbers.
unsigned long RandomBits(long count, long focus);
count
- The number of bits in the number to be generated by the random number generator.
focus
- The degree of clustering about the mean value.
- function result
- A sequence of pseudorandom numbers.
DESCRIPTION
TheRandomBits
function returns random numbers in the range of 0 to 2count
- 1. A focus of 0 generates numbers that are uniformly distributed.A positive value for the
focus
parameter generates numbers that are clustered about the mean, analogous to averaging 2focus
uniform random numbers. A negative focus generates numbers that tend to avoid the mean.If you define a value limit to be 1 <<
count
, the result of theRandomBits
function ranges from 0 to limit - 1. Its mean is (limit - 1) / 2. The mean is independent of the focus. If the focus is positive, the standard deviation of the numbers generated by theRandomBits
function is approximately (0.28868 limit) / e1.41421 focus. As thefocus
parameter gets bigger, two things happen:
If the focus is negative, the
- The values cluster about the mean.
- The values approximate a normal distribution (central limit theorem).
RandomBits
function result is computed as if it were positive; for results less than limit / 2, limit / 2 is added; for others, limit / 2 is subtracted. This causes the distribution to avoid the mean.To generate a clustering of points around a given value, generate x and y offsets with
FractMultiply(radius, RandomBits(31, focus) - fract1);The average distance will be 0.57735 radius/e1.41421 focus.A good way to select a value for the focus is to experiment until the desired result is achieved.
SEE ALSO
TheSetRandomSeed
function sets the starting number seed for the random number generator algorithm. TheSetRandomSeed
function is described in the next section. TheGetRandomSeed
function returns the current starting number seed for the random number generator algorithm. TheGetRandomSeed
function is described on page 8-60.