#include <coherence/util/Random.hpp>
Inherits Object.
This class is an implementation of D. H. Lehmer's linear congruential formula as described by Donald E. Knuth in: The Art of Computer Programming, Volume 2, Section 3.2.1.
Public Types | |
| typedef spec::Handle | Handle |
| Random Handle definition. | |
| typedef spec::View | View |
| Random View definition. | |
| typedef spec::Holder | Holder |
| Random Holder definition. | |
Public Member Functions | |
| virtual int32_t | nextInt32 (int32_t n) |
| Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence. | |
| virtual bool | nextBoolean () |
| Returns the next pseudorandom, uniformly distributed boolean value from this random number generator's sequence. | |
| virtual int32_t | nextInt32 () |
| Returns the next pseudorandom, uniformly distributed int32_t value from this random number generator's sequence. | |
| virtual int64_t | nextInt64 () |
| Returns the next pseudorandom, uniformly distributed int64_t value from this random number generator's sequence. | |
| virtual float32_t | nextFloat32 () |
| Returns the next pseudorandom, uniformly distributed float32_t value from this random number generator's sequence. | |
| virtual float64_t | nextFloat64 () |
| Returns the next pseudorandom, uniformly distributed float64_t value from this random number generator's sequence. | |
| virtual void | seed () |
| Provides a default seeding algorithm that is used to seed this random number if no seed is provided. | |
| virtual void | setSeed (int64_t lSeed) |
| Sets the seed of this random number generator using a single long seed. | |
Static Public Member Functions | |
| static ObjectArray::Handle | randomize (ObjectArray::Handle ha) |
| Randomize the order of the elements within the passed array. | |
| static List::Handle | randomize (List::Handle hl) |
| Randomize the order of the elements within the passed list. | |
| static Handle | getInstance () |
| Return the static Random instance. | |
Protected Member Functions | |
| Random () | |
| Create a new Random instance without supplying a seed. | |
| Random (int64_t lSeed) | |
| Create a new Random instance, specifying a seed to use. | |
| virtual int32_t | next (int32_t nBits) |
| Implementation of the random number algorithm which generates the next pseudorandom number. | |
Protected Attributes | |
| NativeAtomic64 | m_atomicSeed |
| The internal state associated with this pseudorandom number generator. | |
| Random | ( | ) | [protected] |
| virtual int32_t nextInt32 | ( | int32_t | n | ) | [virtual] |
Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.
n the upper bound (exclusive) for the returned value
| IllegalArgumentException | if n is <= 0 |
| virtual bool nextBoolean | ( | ) | [virtual] |
Returns the next pseudorandom, uniformly distributed boolean value from this random number generator's sequence.
| virtual int32_t nextInt32 | ( | ) | [virtual] |
Returns the next pseudorandom, uniformly distributed int32_t value from this random number generator's sequence.
| virtual int64_t nextInt64 | ( | ) | [virtual] |
Returns the next pseudorandom, uniformly distributed int64_t value from this random number generator's sequence.
| virtual float32_t nextFloat32 | ( | ) | [virtual] |
Returns the next pseudorandom, uniformly distributed float32_t value from this random number generator's sequence.
| virtual float64_t nextFloat64 | ( | ) | [virtual] |
Returns the next pseudorandom, uniformly distributed float64_t value from this random number generator's sequence.
| static ObjectArray::Handle randomize | ( | ObjectArray::Handle | ha | ) | [static] |
Randomize the order of the elements within the passed array.
| ha | an array of objects to randomize |
| static List::Handle randomize | ( | List::Handle | hl | ) | [static] |
Randomize the order of the elements within the passed list.
| ha | a list of objects to randomize |
| virtual int32_t next | ( | int32_t | nBits | ) | [protected, virtual] |
Implementation of the random number algorithm which generates the next pseudorandom number.
Generates a 32 bit int value with it's corresponding bits being individually generated pseudorandom 1's and 0's. This method should be overridden to provide a new random number algorithm.
| nBits | number of random bits to generate |
| static Handle getInstance | ( | ) | [static] |