#include <faith/randomsequence.h>
Public Member Functions | |
| RandomSequence (long lngSeed=0) | |
| virtual | ~RandomSequence () |
| RandomSequence (const RandomSequence &a) | |
| RandomSequence & | operator= (const RandomSequence &a) |
| void | setSeed (long lngSeed=1) |
| double | getDouble () |
| unsigned long | getLong (unsigned long max) |
| bool | getBool () |
| void | modulate (int i) |
Static Public Member Functions | |
| static int | random () |
Given a seed number, this class will produce a sequence of random numbers. This would typically be used in applications like games.
In general, you should instantiate a RandomSequence object and pass along your seed number in the constructor. From then on, simply call getDouble or getLong to obtain the next number in the sequence.
| Faith::RandomSequence::RandomSequence | ( | long | lngSeed = 0 |
) |
Creates a random sequence based on the seed lngSeed.
A random sequence is different for each seed but can be reproduced by starting the sequence with the same seed.
If you need a single value which needs to be unpredictable, you need to use random() instead.
| lngSeed | Seed to initialize the sequence with. If lngSeed is 0, the sequence is initialized with a value from KApplication::random(). |
| virtual Faith::RandomSequence::~RandomSequence | ( | ) | [virtual] |
Standard destructor
| Faith::RandomSequence::RandomSequence | ( | const RandomSequence & | a | ) |
Copy constructor
| bool Faith::RandomSequence::getBool | ( | ) |
Get a boolean from the pseudo-random sequence.
| double Faith::RandomSequence::getDouble | ( | ) |
Get the next number from the pseudo-random sequence.
| unsigned long Faith::RandomSequence::getLong | ( | unsigned long | max | ) |
Get the next number from the pseudo-random sequence.
| void Faith::RandomSequence::modulate | ( | int | i | ) |
Modulate the random sequence.
If S(i) is the sequence of numbers that will follow given the current state after calling modulate(i), then S(i) != S(j) for i != j and S(i) == S(j) for i == j.
This can be useful in game situation where "undo" restores the state of the random sequence. If the game modulates the random sequence with the move chosen by the player, the random sequence will be identical whenever the player "redo"-s his or hers original move, but different when the player chooses another move.
With this scenario "undo" can no longer be used to repeat a certain move over and over again until the computer reacts with a favorable response or to predict the response for a certain move based on the response to another move.
| i | the sequence identified |
| RandomSequence& Faith::RandomSequence::operator= | ( | const RandomSequence & | a | ) |
Assignment
| static int Faith::RandomSequence::random | ( | ) | [static] |
| void Faith::RandomSequence::setSeed | ( | long | lngSeed = 1 |
) |
Restart the sequence based on lngSeed.
| lngSeed | Seed to initialize the sequence with. If lngSeed is 0, the sequence is initialized with a value from KApplication::random(). |
1.4.7