Random Value Generator which is used to generate a stream of pseudorandom numbers.
More...
#include <src/main/decaf/util/Random.h>
Public Member Functions |
| Random () |
| Construct a random generator with the current time of day in milliseconds as the initial state.
|
| Random (unsigned long long seed) |
| Construct a random generator with the given seed as the initial state.
|
virtual | ~Random () |
bool | nextBoolean () |
| Answers the next pseudo-random, uniformly distributed boolean value generated by this generator.
|
double | nextDouble () |
| Generates a normally distributed random double number between 0.0 inclusively and 1.0 exclusively.
|
float | nextFloat () |
| Generates a normally distributed random float number between 0.0 inclusively and 1.0 exclusively.
|
double | nextGaussian () |
| Pseudo-randomly generates (approximately) a normally distributed double value with mean 0.0 and a standard deviation value of 1.0 using the polar method of G.
|
int | nextInt () |
| Generates a uniformly distributed 32-bit int value from the this random number sequence.
|
int | nextInt (int n) |
| Returns to the caller a new pseudo-random integer value which is uniformly distributed between 0 (inclusively) and the value of n (exclusively).
|
long long | nextLong () |
| Generates a uniformly distributed 64-bit int value from the this random number sequence.
|
virtual void | nextBytes (std::vector< unsigned char > &buf) |
| Modifies the byte array by a random sequence of bytes generated by this random number generator.
|
virtual void | nextBytes (unsigned char *buf, int size) |
| Modifies the byte array by a random sequence of bytes generated by this random number generator.
|
virtual void | setSeed (unsigned long long seed) |
| Modifies the seed using linear congruential formula presented in The Art of Computer Programming, Volume 2, Section 3.2.1.
|
Protected Member Functions |
virtual int | next (int bits) |
| Answers a pseudo-random uniformly distributed int value of the number of bits specified by the argument bits as described by Donald E.
|
Detailed Description
Random Value Generator which is used to generate a stream of pseudorandom numbers.
The algorithms implemented by class Random use a protected utility method that on each invocation can supply up to 32 pseudorandomly generated bits.
- Since:
- 1.0
Constructor & Destructor Documentation
decaf::util::Random::Random |
( |
| ) |
|
Construct a random generator with the current time of day in milliseconds as the initial state.
- See also:
- setSeed
decaf::util::Random::Random |
( |
unsigned long long |
seed | ) |
|
Construct a random generator with the given seed
as the initial state.
- Parameters:
-
seed | the seed that will determine the initial state of this random number generator |
- See also:
- setSeed
virtual decaf::util::Random::~Random |
( |
| ) |
[virtual] |
Member Function Documentation
virtual int decaf::util::Random::next |
( |
int |
bits | ) |
[protected, virtual] |
bool decaf::util::Random::nextBoolean |
( |
| ) |
|
Answers the next pseudo-random, uniformly distributed boolean value generated by this generator.
- Returns:
- boolean a pseudo-random, uniformly distributed boolean value
virtual void decaf::util::Random::nextBytes |
( |
unsigned char * |
buf, |
|
|
int |
size |
|
) |
| [virtual] |
Modifies the byte array by a random sequence of bytes generated by this random number generator.
- Parameters:
-
buf | non-null array to contain the new random bytes |
- See also:
- next
- Exceptions:
-
NullPointerException | if buff is NULL |
IllegalArgumentException | if size is negative |
Reimplemented in decaf::security::SecureRandom.
virtual void decaf::util::Random::nextBytes |
( |
std::vector< unsigned char > & |
buf | ) |
[virtual] |
Modifies the byte array by a random sequence of bytes generated by this random number generator.
- Parameters:
-
buf | non-null array to contain the new random bytes |
- See also:
- next
Reimplemented in decaf::security::SecureRandom.
double decaf::util::Random::nextDouble |
( |
| ) |
|
Generates a normally distributed random double number between 0.0 inclusively and 1.0 exclusively.
- Returns:
- double
- See also:
- nextFloat
float decaf::util::Random::nextFloat |
( |
| ) |
|
Generates a normally distributed random float number between 0.0 inclusively and 1.0 exclusively.
- Returns:
- float a random float number between 0.0 and 1.0
- See also:
- nextDouble
double decaf::util::Random::nextGaussian |
( |
| ) |
|
Pseudo-randomly generates (approximately) a normally distributed double
value with mean 0.0 and a standard deviation value of 1.0
using the polar method of G.
E. P. Box, M. E. Muller, and G. Marsaglia, as described by Donald E. Knuth in The Art of Computer Programming, Volume 2: Seminumerical Algorithms, section 3.4.1, subsection C, algorithm P
- Returns:
- double
- See also:
- nextDouble
int decaf::util::Random::nextInt |
( |
| ) |
|
Generates a uniformly distributed 32-bit int
value from the this random number sequence.
- Returns:
- int uniformly distributed
int
value
- See also:
- next
-
nextLong
int decaf::util::Random::nextInt |
( |
int |
n | ) |
|
Returns to the caller a new pseudo-random integer value which is uniformly distributed between 0 (inclusively) and the value of n
(exclusively).
- Parameters:
-
n | The int value that defines the max value of the return. |
- Returns:
- the next pseudo random int value.
- Exceptions:
-
IllegalArgumentException | if n is less than or equal to zero. |
long long decaf::util::Random::nextLong |
( |
| ) |
|
Generates a uniformly distributed 64-bit int
value from the this random number sequence.
- Returns:
- 64-bit
int
random number
- See also:
- next
-
nextInt()
-
nextInt(int)
virtual void decaf::util::Random::setSeed |
( |
unsigned long long |
seed | ) |
[virtual] |
Modifies the seed using linear congruential formula presented in The Art of Computer Programming, Volume 2, Section 3.2.1.
- Parameters:
-
seed | the seed that alters the state of the random number generator |
- See also:
- next
-
Random()
-
#Random(long)
Reimplemented in decaf::security::SecureRandom.
The documentation for this class was generated from the following file: