Represents a random number generator.
More...
#include <arithmetic-gmp.hpp>
Represents a random number generator.
As the underlying generator, the Mersenne Twister is used.
- Warning
- Note that while this random number generator is perfectly fine for most purposes, it is not for cryptographical purposes.
Definition at line 3281 of file arithmetic-gmp.hpp.
static Integer plll::arithmetic::RandomNumberGenerator::createSeed |
( |
| ) |
|
|
static |
Integer plll::arithmetic::RandomNumberGenerator::getSeed |
( |
| ) |
const |
Retrieves the last set seed of the generator.
- Returns
- The previously set seed.
static void plll::arithmetic::RandomNumberGenerator::initializeSeeder |
( |
double |
goodness = 0.01 | ) |
|
|
static |
Calls randomizeDevRandom(goodness)
for the internal random number generator which is used for createSeed()
.
Allows to initialize the internal random number generator at this point of time. If RandomNumberGenerator::createSeed()
is then called later during the program, no blocking will occur at that point.
- Warning
- This call might block until enough entropy is available to the operating system.
- See also
RandomNumberGenerator::createSeed()
Copies the state of the given random number generator to the current one.
- Parameters
-
rng | The random number generator whose state should be copied. |
- Returns
- A reference to the current random number generator.
void plll::arithmetic::RandomNumberGenerator::random |
( |
Integer & |
res, |
|
|
const Integer & |
bound |
|
) |
| |
Creates a random arbitrary precision integer in the range .
- Parameters
-
res | Where to store the result. |
bound | A bound on the maximal integer returned. |
Integer plll::arithmetic::RandomNumberGenerator::random |
( |
const Integer & |
bound | ) |
|
Creates and returns a random arbitrary precision integer in the range .
- Parameters
-
bound | A bound on the maximal integer returned. |
- Returns
- The result.
unsigned long plll::arithmetic::RandomNumberGenerator::random |
( |
unsigned long |
bound | ) |
|
Creates and returns a native integer in the range .
- Parameters
-
bound | A bound on the maximal integer returned. |
- Returns
- The result.
void plll::arithmetic::RandomNumberGenerator::randomBits |
( |
void * |
ptr, |
|
|
unsigned long |
count |
|
) |
| |
Writes a given number of random bytes to the memory location pointed to.
- Parameters
-
ptr | A pointer to the memory location. |
count | The number of bytes to write there. |
void plll::arithmetic::RandomNumberGenerator::randomBits |
( |
Integer & |
res, |
|
|
unsigned long |
bits |
|
) |
| |
Creates random bits.
- Parameters
-
res | Will be filled with a random integer in range . |
bits | The number of bits. |
Integer plll::arithmetic::RandomNumberGenerator::randomBits |
( |
unsigned long |
bits | ) |
|
Creates random bits.
- Parameters
-
- Returns
- A random integer in range .
void plll::arithmetic::RandomNumberGenerator::randomizeDevRandom |
( |
double |
goodness = 0.01 | ) |
|
Uses the operating system's random number generator to initialize this random number generator.
- Parameters
-
goodness | Specify how much of the state should be taken from /dev/random instead of /dev/urandom. The default fraction is very small, to minimize the amount of blocking when trying to read too much from /dev/random. A value of 0.0 reads everything from /dev/urandom, and thus might be completely predictable to a watcher, while a value of 1.0 reads everything from /dev/random, resulting in a state completely independent from previously read random values. |
For most purposes, the default value 0.01 is totally fine, and even 0.0 is fine in many cases. Note that only a value of 0.0 garuantees that absolutely no blocking occurs.
void plll::arithmetic::RandomNumberGenerator::randomizeSeed |
( |
| ) |
|
Initializes this random number generator with a random seed.
Equivalent to setSeed(RandomNumberGenerator::createSeed())
.
void plll::arithmetic::RandomNumberGenerator::randomizeTime |
( |
| ) |
|
Uses the system's time to seed this random number generator.
- Warning
- This is implementation dependent and might behave completely different even on the same system if two programs are run at the precisely same time.
void plll::arithmetic::RandomNumberGenerator::randomLen |
( |
Integer & |
res, |
|
|
unsigned long |
bits |
|
) |
| |
Creates a random integer of a fixed bit length.
- Parameters
-
res | Will be filled with a random integer in range . |
bits | The number of bits. |
Integer plll::arithmetic::RandomNumberGenerator::randomLen |
( |
unsigned long |
bits | ) |
|
Creates a random integer of a fixed bit length.
- Parameters
-
- Returns
- A random integer in range .
void plll::arithmetic::RandomNumberGenerator::randomUniform |
( |
Real & |
r | ) |
|
Creates a uniformly distributed floating point number in the interval .
- Parameters
-
r | Where to store the result. |
void plll::arithmetic::RandomNumberGenerator::randomUniform |
( |
Real & |
r, |
|
|
const RealContext & |
rc |
|
) |
| |
Creates a uniformly distributed floating point number in the interval .
- Parameters
-
r | Where to store the result. |
rc | The context whose precision to use for the result. |
Real plll::arithmetic::RandomNumberGenerator::randomUniform |
( |
| ) |
|
|
inline |
Creates and returns a uniformly distributed floating point number in the interval .
- Returns
- The random number.
Definition at line 3476 of file arithmetic-gmp.hpp.
Real plll::arithmetic::RandomNumberGenerator::randomUniform |
( |
const RealContext & |
rc | ) |
|
|
inline |
Creates and returns a uniformly distributed floating point number in the interval .
- Parameters
-
rc | The context whose precision to use for the result. |
- Returns
- The random number.
Definition at line 3490 of file arithmetic-gmp.hpp.
void plll::arithmetic::RandomNumberGenerator::setSeed |
( |
const Integer & |
seed | ) |
|
Sets a new seed for the generator.
The state is generated from this seed, so a short or small seed does not lead to a bad state.
- Parameters
-
seed | The integer to use as a seed. |
The documentation for this class was generated from the following file: