activemq-cpp-3.6.0
decaf::util::Random Class Reference

Random Value Generator which is used to generate a stream of pseudorandom numbers. More...

#include <src/main/decaf/util/Random.h>

Inheritance diagram for decaf::util::Random:

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
seedthe 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)
protectedvirtual

Answers a pseudo-random uniformly distributed int value of the number of bits specified by the argument bits as described by Donald E.

Knuth in The Art of Computer Programming, Volume 2: Seminumerical Algorithms, section 3.2.1.

Returns
int a pseudo-random generated int number
Parameters
bitsnumber of bits of the returned value
See Also
nextBytes
nextDouble
nextFloat
nextInt()
nextInt(int)
nextGaussian
nextLong

Reimplemented in decaf::security::SecureRandom.

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 ( std::vector< unsigned char > &  buf)
virtual

Modifies the byte array by a random sequence of bytes generated by this random number generator.

Parameters
bufnon-null array to contain the new random bytes
See Also
next

Reimplemented in decaf::security::SecureRandom.

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
bufnon-null array to contain the new random bytes
See Also
next
Exceptions
NullPointerExceptionif buff is NULL
IllegalArgumentExceptionif size is negative

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
nThe int value that defines the max value of the return.
Returns
the next pseudo random int value.
Exceptions
IllegalArgumentExceptionif 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
seedthe 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: