digiKam
|
Public Member Functions | |
quint32 | currentSeed () const |
double | number (double min, double max) |
int | number (int min, int max) |
RandomNumberGenerator () | |
void | reseed () |
void | seed (quint32 seed) |
quint32 | seedByTime () |
quint32 | seedNonDeterministic () |
bool | yesOrNo (double p) |
~RandomNumberGenerator () | |
Static Public Member Functions | |
static quint32 | nonDeterministicSeed () |
static quint32 | timeSeed () |
This class differs from standard pseudo random number generators (rand()) in these points:
|
explicit |
Constructs a random number generator that is seeded with a constant value. It is recommended to call a seed method after construction.
Digikam::RandomNumberGenerator::~RandomNumberGenerator | ( | ) |
quint32 Digikam::RandomNumberGenerator::currentSeed | ( | ) | const |
Retrieves the current seed. Can be used for seed(quint32) to replay the results again.
|
static |
Produces a non-deterministic seed, as used by seedNonDeterministic()
References seed().
Referenced by seedNonDeterministic().
double Digikam::RandomNumberGenerator::number | ( | double | min, |
double | max | ||
) |
Returns a random double in the interval [min, max) (including min, excluding max) Warning: this method is non re-entrant.
int Digikam::RandomNumberGenerator::number | ( | int | min, |
int | max | ||
) |
Returns a random integer in the interval [min, max] (including min and max). Warning: this method is non re-entrant.
Referenced by Digikam::DImg::convertDepth().
void Digikam::RandomNumberGenerator::reseed | ( | ) |
Seeds the generator again with the currentSeed(). This is not a no-op, rather, the sequence of random numbers starts again from its beginning after each re-seed. Equivalent to seed(currentSeed())
References seed().
void Digikam::RandomNumberGenerator::seed | ( | quint32 | seed | ) |
Seeds the generator with the given value. This is not meant to be called with a constant value, but with a value retrieved from currentSeed() on a previous run. Across platforms, the same sequence of random numbers will be generated for the same seed.
Referenced by nonDeterministicSeed(), reseed(), and timeSeed().
quint32 Digikam::RandomNumberGenerator::seedByTime | ( | ) |
Seeds the generator by current time. This is common practice and good enough for most purposes. Returns the new currentSeed().
References timeSeed().
quint32 Digikam::RandomNumberGenerator::seedNonDeterministic | ( | ) |
Seeds the generator from a non-deterministic random number generator. This is the most secure seeding method. Returns the new currentSeed().
References nonDeterministicSeed().
|
static |
Produces a seed that includes at least the time as source of random data
References seed().
Referenced by Digikam::DistortionFXFilter::DistortionFXFilter(), and seedByTime().
bool Digikam::RandomNumberGenerator::yesOrNo | ( | double | p | ) |
Returns true with a probability of p (where p shall be in the interval [0, 1]) Warning: this method is non re-entrant.