digiKam Developer Documentation: Digikam::RandomNumberGenerator Class Reference

| digiKam Developer Documentation Professional Photo Management with the Power of Open Source

Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
Digikam::RandomNumberGenerator Class Reference

This class differs from standard pseudo random number generators (rand()) in these points: More...

## Public Member Functions
| RandomNumberGenerator ()
| Constructs a random number generator that is seeded with a constant value.
quint32 | currentSeed () const
| Retrieves the current seed.
double | number (double min, double max)
int | number (int min, int max)
void | reseed ()
| Seeds the generator again with the currentSeed().
void | seed (quint32 seed)
| Seeds the generator with the given value.
quint32 | seedByTime ()
| Seeds the generator by current time.
quint32 | seedNonDeterministic ()
| Seeds the generator from a non-deterministic random number generator.
bool | yesOrNo (double p)

## Static Public Member Functions
static quint32 | nonDeterministicSeed ()
| Produces a non-deterministic seed, as used by seedNonDeterministic()
static quint32 | timeSeed ()
| Produces a seed that includes at least the time as source of random data.

## Detailed Description

- it uses a specified, independently implemented algorithm identical across platforms
- provides access to the used seed
- it can thus guarantee replayable sequences
- it provides convenient seeding of varying quality

## Constructor & Destructor Documentation

## ◆ RandomNumberGenerator()

Digikam::RandomNumberGenerator::RandomNumberGenerator | ( |  | ) |
| explicit

It is recommended to call a seed method after construction.

## Member Function Documentation

## ◆ currentSeed()

quint32 Digikam::RandomNumberGenerator::currentSeed | ( |  | ) | const

Can be used for seed(quint32) to replay the results again.

## ◆ number() [1/2]

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.

## ◆ number() [2/2]

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.

## ◆ reseed()

void Digikam::RandomNumberGenerator::reseed | ( |  | ) |

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())

## ◆ seed()

void Digikam::RandomNumberGenerator::seed | ( | quint32 | seed | ) |

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.

## ◆ seedByTime()

quint32 Digikam::RandomNumberGenerator::seedByTime | ( |  | ) |

This is common practice and good enough for most purposes.

Returns
  the new currentSeed().

## ◆ seedNonDeterministic()

quint32 Digikam::RandomNumberGenerator::seedNonDeterministic | ( |  | ) |

This is the most secure seeding method.

Returns
  the new currentSeed().

## ◆ yesOrNo()

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.