Main Page   Modules   Alphabetical List   Data Structures   Data Fields  

RpRandom
[Math Tools]


Functions

void  RpRandomSeedMT (RwUInt32 seed)
RwUInt32  RpRandomMT (void)
void  RpRandomSeed (RwUInt32 seed)
RwUInt32  RpRandom (void)
RwBool  RpRandomPluginAttach (void)

Detailed Description

Random Number Generation Plugin for RenderWare Graphics.

RpRandom Plugin Overview

Requirements

Overview

This plugin provides a 31-bit pseudo-random number generator using a linear feedback shift register approach using trinomials. It is based on research performed at the University of California, Berkeley. (1983, 1993). All 31 bits may be considered random.

It is provided as a RenderWare Graphics Plugin as a replacement for generators used in the standard C libraries. This allows consistent random number generation across all our supported platforms.


Function Documentation

RwUInt32 RpRandom void   
 

RpRandom is used to generate a 31-bit pseudo-random number. It uses a non-linear additive feedback random number generator employing a default table of size 31 long integers to return successive pseudo-random numbers in the range 0 to pow(2,31)-1. The period of this random number generator is very large, approximately 16(pow(2,31)-1).

Note that all the bits generated by RpRandom are usable, for example RpRandom() &01 will produce a random binary value.

The random number plugin must be attached before using this function.

Returns:
a RwUInt32 value containing a pseudo-random number
See also:
RpRandomSeed
RwUInt32 RpRandomMT void   
 

RpRandomMT is used to generate ``Mersenne Twister'' (MT19937) random numbers. The Mersenne Twister generator produces pseudorandom integers uniformly distributed in 0..(2^32 - 1) starting from any odd seed in 0..(2^32 - 1).

According to the URL <http://www.math.keio.ac.jp/~matumoto/emt.html> (and paraphrasing a bit in places), the Mersenne Twister is ``designed with consideration of the flaws of various existing generators,'' has a period of 2^19937 - 1, gives a sequence that is 623-dimensionally equidistributed, and ``has passed many stringent tests, including the die-hard test of G. Marsaglia and the load test of P. Hellekalek and S. Wegenkittl.'' It is efficient in memory usage (typically using 2506 to 5012 bytes of static data, depending on data type sizes, and the code is quite short as well). It generates random numbers in batches of 624 at a time, so the caching and pipelining of modern systems is exploited. It is also divide- and mod- free.

The random number plugin must be attached before using this function.

Returns:
a RwUInt32 value containing a pseudo-random number
See also:
RpRandomSeedMT
RwBool RpRandomPluginAttach void   
 

RpRandomPluginAttach is used to attach the random number plugin to the RenderWare system to enable the generation of random integer values. The random plugin must be attached between initializing the system with RwEngineInit and opening it with RwEngineOpen.

Note that the include file rprandom.h is required and must be included by an application wishing to use random numbers. The random plugin library is contained in the file rprandom.lib

The call to this function should occur after RwEngineInit.

Returns:
True on success, false otherwise.
See also:
RwEngineInit , RwEngineOpen , RwEngineStart
void RpRandomSeed RwUInt32    seed
 

RpRandomSeed is used to initialize the random number generator using the specified seed value.

Note that this function does not return the old seed. Therefore, if it is required to reproduce a sequence of random numbers, the seed must be set with a user-defined value before any numbers are generated. The seed can then be used again to generate the same numbers.

The random number plugin must be attached before using this function.

Parameters:
seed  The seed value for random number generation.
See also:
RpRandom
void RpRandomSeedMT RwUInt32    seed
 

RpRandomSeedMT is used to initialize the Mersenne Twister random number generator using the specified seed value.

Note that this function does not return the old seed. Therefore, if it is required to reproduce a sequence of random numbers, the seed must be set with a user-defined value before any numbers are generated. The seed can then be used again to generate the same numbers.

The random number plugin must be attached before using this function.

Parameters:
seed  The seed value for random number generation.
See also:
RpRandomMT

Criterion Software © 1993-2003 Criterion Software Limited. All rights reserved. Built Tue Apr 22 12:46:28 2003. Send Feedback
Converted from CHM to HTML with chm2web Pro 2.85 (unicode)