Game Development Reference
In-Depth Information
private:
// DATA
unsigned int rseed;
unsigned int rseed_sp;
unsigned long mt[CMATH_N]; /* the array for the state vector */
int mti; /* mti==N+1 means mt[N] is not initialized */
// FUNCTIONS
public:
GCCRandom(void);
unsigned int Random( unsigned int n );
float Random( );
void SetRandomSeed(unsigned int n);
unsigned int GetRandomSeed(void);
void
Randomize(void);
};
The original code has been modified to include a few useful bits, one of which was to
allow this class to save and reload its random number seed, which can be used to
replay random number sequences by simply storing the seed. Here
'
s an example of
how you can use the class:
GCCRandom r;
r.Randomize();
unsigned int num = r.Random(100); // returns a number from 0-99, inclusive
You should use a few instantiations of this class in your game, each one generating
random numbers for a different part of your game. Here
s say you want to
generate some random taunts from AI characters. If you use a different random
number sequence from the sequence that generates the contents of treasure chests,
you can be sure that if the player turns off character audio, the same RNG sequence
will result for the treasure chests, which nicely compartmentalizes your game. In
other words, your game becomes predictable and testable.
'
s why: Let
'
Your Random Number Generator Can Break Automation
I was working on an automation system for some Microsoft games, and the
thing would just not work right. The goal of the system was to be able to
record game sessions and play them back. The system was great for testers
and programmers alike. It
s hard, and boring, to play a few million hands of
blackjack. Our programming team realized that since the same RNG was
being called for every system of the game, small aberrations would occur
as calls to the RNG went out of sync. This was especially true for random
character audio, since the timing of character audio was completely
'
 
Search WWH ::




Custom Search