OpenShot Library | libopenshot-audio
0.1.9
|
A random number generator. More...
#include <juce_Random.h>
Public Member Functions | |
Random (int64 seedValue) noexcept | |
Creates a Random object based on a seed value. More... | |
Random () | |
Creates a Random object using a random seed value. More... | |
~Random () noexcept | |
Destructor. More... | |
int | nextInt () noexcept |
Returns the next random 32 bit integer. More... | |
int | nextInt (int maxValue) noexcept |
Returns the next random number, limited to a given range. More... | |
int | nextInt (Range< int > range) noexcept |
Returns the next random number, limited to a given range. More... | |
int64 | nextInt64 () noexcept |
Returns the next 64-bit random number. More... | |
float | nextFloat () noexcept |
Returns the next random floating-point number. More... | |
double | nextDouble () noexcept |
Returns the next random floating-point number. More... | |
bool | nextBool () noexcept |
Returns the next random boolean value. More... | |
BigInteger | nextLargeNumber (const BigInteger &maximumValue) |
Returns a BigInteger containing a random number. More... | |
void | fillBitsRandomly (void *bufferToFill, size_t sizeInBytes) |
Fills a block of memory with random values. More... | |
void | fillBitsRandomly (BigInteger &arrayToChange, int startBit, int numBits) |
Sets a range of bits in a BigInteger to random values. More... | |
void | setSeed (int64 newSeed) noexcept |
Resets this Random object to a given seed value. More... | |
int64 | getSeed () const noexcept |
Returns the RNG's current seed. More... | |
void | combineSeed (int64 seedValue) noexcept |
Merges this object's seed with another value. More... | |
void | setSeedRandomly () |
Reseeds this generator using a value generated from various semi-random system properties like the current time, etc. More... | |
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. More... | |
A random number generator.
You can create a Random object and use it to generate a sequence of random numbers.
Definition at line 38 of file juce_Random.h.
|
explicitnoexcept |
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())
Definition at line 26 of file juce_Random.cpp.
juce::Random::Random | ( | ) |
Creates a Random object using a random seed value.
Internally, this calls setSeedRandomly() to randomise the seed.
Definition at line 30 of file juce_Random.cpp.
References setSeedRandomly().
|
noexcept |
Destructor.
Definition at line 35 of file juce_Random.cpp.
|
noexcept |
Returns the next random 32 bit integer.
Definition at line 78 of file juce_Random.cpp.
Referenced by juce::TextDiff::Change::appliedTo(), juce::FloatVectorOperations::areDenormalsDisabled(), fillBitsRandomly(), juce::BigInteger::loadFromMemoryBlock(), nextBool(), nextDouble(), nextFloat(), nextInt(), nextInt64(), juce::JSON::parseQuotedString(), juce::UnitTestRunner::runTests(), juce::GZIPCompressorOutputStream::setPosition(), juce::MemoryInputStream::skipNextBytes(), juce::StringRef::StringRef(), juce::Base64::toBase64(), juce::Uuid::Uuid(), juce::ValueTree::Listener::valueTreeRedirected(), and juce::AbstractFifo::write().
|
noexcept |
Returns the next random number, limited to a given range.
The maxValue parameter may not be negative, or zero.
Definition at line 85 of file juce_Random.cpp.
References nextInt().
|
noexcept |
Returns the next random number, limited to a given range.
Definition at line 91 of file juce_Random.cpp.
References nextInt().
|
noexcept |
Returns the next 64-bit random number.
Definition at line 96 of file juce_Random.cpp.
References nextInt().
Referenced by combineSeed(), juce::JSON::parseQuotedString(), and juce::MemoryInputStream::skipNextBytes().
|
noexcept |
Returns the next random floating-point number.
Definition at line 106 of file juce_Random.cpp.
References nextInt().
Referenced by fillBitsRandomly().
|
noexcept |
Returns the next random floating-point number.
Definition at line 111 of file juce_Random.cpp.
References nextInt().
Referenced by juce::FloatVectorOperations::areDenormalsDisabled(), fillBitsRandomly(), juce::JSON::parseQuotedString(), juce::MemoryInputStream::skipNextBytes(), and juce::ValueTree::Listener::valueTreeRedirected().
|
noexcept |
Returns the next random boolean value.
Definition at line 101 of file juce_Random.cpp.
References nextInt().
Referenced by juce::FloatVectorOperations::areDenormalsDisabled(), fillBitsRandomly(), juce::JSON::parseQuotedString(), juce::MemoryInputStream::skipNextBytes(), juce::StringRef::StringRef(), and juce::ValueTree::Listener::valueTreeRedirected().
BigInteger juce::Random::nextLargeNumber | ( | const BigInteger & | maximumValue | ) |
Returns a BigInteger containing a random number.
Definition at line 116 of file juce_Random.cpp.
References fillBitsRandomly(), and juce::BigInteger::getHighestBit().
void juce::Random::fillBitsRandomly | ( | void * | bufferToFill, |
size_t | sizeInBytes | ||
) |
Fills a block of memory with random values.
Definition at line 129 of file juce_Random.cpp.
References nextInt().
Referenced by juce::BigInteger::loadFromMemoryBlock(), and nextLargeNumber().
void juce::Random::fillBitsRandomly | ( | BigInteger & | arrayToChange, |
int | startBit, | ||
int | numBits | ||
) |
Sets a range of bits in a BigInteger to random values.
Definition at line 143 of file juce_Random.cpp.
References nextBool(), nextDouble(), nextFloat(), nextInt(), juce::BigInteger::setBit(), and juce::BigInteger::setBitRangeAsInt().
|
noexcept |
Resets this Random object to a given seed value.
Definition at line 39 of file juce_Random.cpp.
References getSystemRandom().
|
inlinenoexcept |
Returns the RNG's current seed.
Definition at line 110 of file juce_Random.h.
|
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.
Definition at line 54 of file juce_Random.cpp.
References nextInt64().
Referenced by setSeedRandomly(), and juce::AbstractFifo::write().
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.
Definition at line 59 of file juce_Random.cpp.
References combineSeed(), juce::Time::currentTimeMillis(), juce::Time::getHighResolutionTicks(), juce::Time::getHighResolutionTicksPerSecond(), and juce::Time::getMillisecondCounter().
Referenced by Random().
|
staticnoexcept |
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..
Definition at line 71 of file juce_Random.cpp.
Referenced by juce::File::createTempFile(), juce::URL::getChildURL(), and setSeed().