JUCE
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
Public Member Functions | Static Public Member Functions
Random Class Reference

A random number generator. More...

List of all members.

Public Member Functions

 Random (int64 seedValue) noexcept
 Creates a Random object based on a seed value.
 Random ()
 Creates a Random object using a random seed value.
 ~Random () noexcept
 Destructor.
int nextInt () noexcept
 Returns the next random 32 bit integer.
int nextInt (int maxValue) noexcept
 Returns the next random number, limited to a given range.
int64 nextInt64 () noexcept
 Returns the next 64-bit random number.
float nextFloat () noexcept
 Returns the next random floating-point number.
double nextDouble () noexcept
 Returns the next random floating-point number.
bool nextBool () noexcept
 Returns the next random boolean value.
BigInteger nextLargeNumber (const BigInteger &maximumValue)
 Returns a BigInteger containing a random number.
void fillBitsRandomly (BigInteger &arrayToChange, int startBit, int numBits)
 Sets a range of bits in a BigInteger to random values.
void setSeed (int64 newSeed) noexcept
 Resets this Random object to a given seed value.
void combineSeed (int64 seedValue) noexcept
 Merges this object's seed with another value.
void setSeedRandomly ()
 Reseeds this generator using a value generated from various semi-random system properties like the current time, etc.

Static Public Member Functions

static RandomgetSystemRandom () noexcept
 The overhead of creating a new Random object is fairly small, but if you want to avoid it, you can call this method to get a global shared Random object.

Detailed Description

A random number generator.

You can create a Random object and use it to generate a sequence of random numbers.


Constructor & Destructor Documentation

Random::Random ( int64  seedValue) [explicit]

Creates a Random object based on a seed value.

For a given seed value, the subsequent numbers generated by this object will be predictable, so a good idea is to set this value based on the time, e.g.

new Random (Time::currentTimeMillis())

Creates a Random object using a random seed value.

Internally, this calls setSeedRandomly() to randomise the seed.

Destructor.


Member Function Documentation

int Random::nextInt ( )

Returns the next random 32 bit integer.

Returns:
a random integer from the full range 0x80000000 to 0x7fffffff
int Random::nextInt ( int  maxValue)

Returns the next random number, limited to a given range.

The maxValue parameter may not be negative, or zero.

Returns:
a random integer between 0 (inclusive) and maxValue (exclusive).

Returns the next 64-bit random number.

Returns:
a random integer from the full range 0x8000000000000000 to 0x7fffffffffffffff
float Random::nextFloat ( )

Returns the next random floating-point number.

Returns:
a random value in the range 0 to 1.0
double Random::nextDouble ( )

Returns the next random floating-point number.

Returns:
a random value in the range 0 to 1.0
bool Random::nextBool ( )

Returns the next random boolean value.

BigInteger Random::nextLargeNumber ( const BigInteger maximumValue)

Returns a BigInteger containing a random number.

Returns:
a random value in the range 0 to (maximumValue - 1).
void Random::fillBitsRandomly ( BigInteger arrayToChange,
int  startBit,
int  numBits 
)

Sets a range of bits in a BigInteger to random values.

void Random::setSeed ( int64  newSeed)

Resets this Random object to a given seed value.

void Random::combineSeed ( int64  seedValue)

Merges this object's seed with another value.

This sets the seed to be a value created by combining the current seed and this new value.

Reseeds this generator using a value generated from various semi-random system properties like the current time, etc.

Because this function convolves the time with the last seed value, calling it repeatedly will increase the randomness of the final result.

static Random& Random::getSystemRandom ( ) [static]

The overhead of creating a new Random object is fairly small, but if you want to avoid it, you can call this method to get a global shared Random object.

It's not thread-safe though, so threads should use their own Random object, otherwise you run the risk of your random numbers becoming.. erm.. randomly corrupted..


The documentation for this class was generated from the following file: