Loading...
Searching...
No Matches
juce::Random Class Referencefinal

## Detailed Description

A random number generator.

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

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

- juce_core/maths/juce_Random.h

## 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.
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.
int | nextInt (Range< int > range) 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 (void *bufferToFill, size_t sizeInBytes)
| Fills a block of memory with random values.
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.
int64 | getSeed () const noexcept
| Returns the RNG's current seed.
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 Random & | getSystemRandom () 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.

## Constructors and Destructors

## Random() [1/2]

juce::Random::Random | ( | int64 | seedValue | ) |

explicit noexcept

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())

Referenced by getSystemRandom().

## Random() [2/2]

juce::Random::Random | ( |  | ) |

Creates a Random object using a random seed value.

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

## Member Functions

## nextInt() [1/3]

int juce::Random::nextInt | ( |  | ) |

noexcept

Returns the next random 32 bit integer.

Returns
  a random integer from the full range 0x80000000 to 0x7fffffff

Referenced by juce::midi_ci::DeviceOptions::makeProductInstanceId(), juce::midi_ci::MUID::makeRandom(), nextInt(), and nextInt().

## nextInt() [2/3]

int juce::Random::nextInt | ( | int | maxValue | ) |

noexcept

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).

References nextInt().

## nextInt() [3/3]

int juce::Random::nextInt | ( | Range< int > | range | ) |

noexcept

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

Returns
  a random integer between the range start (inclusive) and its end (exclusive).

References nextInt().

## nextInt64()

int64 juce::Random::nextInt64 | ( |  | ) |

noexcept

Returns the next 64-bit random number.

Returns
  a random integer from the full range 0x8000000000000000 to 0x7fffffffffffffff

References nextInt64().

Referenced by nextInt64().

## nextFloat()

float juce::Random::nextFloat | ( |  | ) |

noexcept

Returns the next random floating-point number.

Returns
  a random value in the range 0 (inclusive) to 1.0 (exclusive)

References nextFloat().

Referenced by nextFloat().

## nextDouble()

double juce::Random::nextDouble | ( |  | ) |

noexcept

Returns the next random floating-point number.

Returns
  a random value in the range 0 (inclusive) to 1.0 (exclusive)

References nextDouble().

Referenced by nextDouble().

## nextBool()

bool juce::Random::nextBool | ( |  | ) |

noexcept

Returns the next random boolean value.

References nextBool().

Referenced by nextBool().

## nextLargeNumber()

BigInteger juce::Random::nextLargeNumber | ( | const BigInteger & | maximumValue | ) |

Returns a BigInteger containing a random number.

Returns
  a random value in the range 0 to (maximumValue - 1).

References nextLargeNumber().

Referenced by nextLargeNumber().

## fillBitsRandomly() [1/2]

void juce::Random::fillBitsRandomly | ( | void * | bufferToFill,
|  | size_t | sizeInBytes )

Fills a block of memory with random values.

References fillBitsRandomly().

Referenced by fillBitsRandomly(), and fillBitsRandomly().

## fillBitsRandomly() [2/2]

void juce::Random::fillBitsRandomly | ( | BigInteger & | arrayToChange,
|  | int | startBit,
|  | int | numBits )

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

References fillBitsRandomly().

## setSeed()

void juce::Random::setSeed | ( | int64 | newSeed | ) |

noexcept

Resets this Random object to a given seed value.

References setSeed().

Referenced by setSeed().

## getSeed()

int64 juce::Random::getSeed | ( |  | ) | const

inline noexcept

Returns the RNG's current seed.

References getSeed().

Referenced by getSeed().

## combineSeed()

void juce::Random::combineSeed | ( | int64 | seedValue | ) |

noexcept

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.

## setSeedRandomly()

void juce::Random::setSeedRandomly | ( |  | ) |

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.

## getSystemRandom()

Random & juce::Random::getSystemRandom | ( |  | ) |

static 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.

Note this will return a different object per thread it's accessed from, making it thread safe. However, it's therefore important not store a reference to this object that will later be accessed from other threads.

References Random().

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited