![]() |
![]() |
![]() |
![]() |
24 Random Number Generators (rand.hhf)
The rand.hhf header file contains definitions for HLA's random number generators. These functions provide a variety of pseudo-random number generators and support routines. The supplied routines include the following:
rand.randomize;This function "randomizes" the seed used by the random number generators. If you call rand.randomize, the random number generators should begin generating a sequence starting at a random point in the normal sequence put out by the random number generator.
The randomization function is based on the number of CPU clock cycles that have occurred since the CPU was last powered up. This function uses the Pentium's RDTSC instruction, hence you should only call this function on machines that have this instruction available (Intel Pentium and later as well as other manufacturer's CPUs that have this instruction).
Because of the nature of the RDTSC instruction, you should not call rand.randomize frequently or you will compromise the quality of the random numbers (indeed, it's generally not a good idea to "randomize" a random number generator more than once per program invocation). Similarly, you should avoid calling this function from a fixed script after power-on since that may also degrade the quality of the randomization. (These two suggestions are only important to those who are extremely concerned about the quality of the randomness of the generated numbers).
rand.uniform; @returns( "eax" );This function generates a new random number on each call. This function returns a new 32-bit value in the EAX register on each call (bit 31 is randomly set, you may choose to interpret this value as a signed or unsigned integer). This function generates uniformly-distributed random numbers.
rand.urange( startRange:int32; endRange:int32 ); @returns( "eax" );This function generates a uniformly distributed random number in the range "startRange..endRange" (inclusive). This function generates its random numbers using the rand.uniform function. This function returns the value in the EAX register.
rand.random; @returns( "eax" );This function generates a uniformly distributed random number using a linear congruential random number generator. It returns its result in the EAX register.
rand.range( startRange:int32; endRange:int32 ); @returns( "eax" );This function generates a uniformly distributed random number in the range "startRange..endRange" (inclusive). This function generates its random numbers using the rand.random function. This function returns the value in the EAX register.
rand.deal( count:uns32 ); // Iterator returns value in EAX.The rand.deal iterator returns a sequence of count unique randomly arranged values in the range 0..count-1. Therefore, it returns all values in the range 0..count-1, but in a random order.
Since rand.deal is an iterator, you must only use it within a FOREACH loop, e.g.,
foreach deal( 52 ) do << EAX contains a value in the range 1..51 here>> endfor;This function uses the rand.uniform function to randomly arrange the values.
![]() |
![]() |
![]() |
![]() |
![]() |