41 if (
this == &getSystemRandom())
80 seed = (int64) (((((
uint64) seed) * 0x5deece66dLL) + 11) & 0xffffffffffffLL);
82 return (
int) (seed >> 16);
87 jassert (maxValue > 0);
88 return (
int) ((((
unsigned int) nextInt()) * (
uint64) maxValue) >> 32);
93 return range.getStart() + nextInt (range.getLength());
103 return (
nextInt() & 0x40000000) != 0;
108 return static_cast<uint32> (
nextInt()) / (std::numeric_limits<uint32>::max() + 1.0f);
113 return static_cast<uint32> (
nextInt()) / (std::numeric_limits<uint32>::max() + 1.0);
131 int* d =
static_cast<int*
> (buffer);
172 void runTest()
override
174 beginTest (
"Random");
176 Random r = getRandom();
178 for (
int i = 2000; --i >= 0;)
180 expect (r.nextDouble() >= 0.0 && r.nextDouble() < 1.0);
181 expect (r.nextFloat() >= 0.0f && r.nextFloat() < 1.0f);
182 expect (r.nextInt (5) >= 0 && r.nextInt (5) < 5);
183 expect (r.nextInt (1) == 0);
185 int n = r.nextInt (50) + 1;
186 expect (r.nextInt (
n) >= 0 && r.nextInt (
n) <
n);
188 n = r.nextInt (0x7ffffffe) + 1;
189 expect (r.nextInt (
n) >= 0 && r.nextInt (
n) <
n);
194static RandomTests randomTests;
Holds a resizable array of primitive or copy-by-value objects.
Array()=default
Creates an empty array.
An arbitrarily large integer class.
A random number generator.
float nextFloat() noexcept
Returns the next random floating-point number.
Random()
Creates a Random object using a random seed value.
void fillBitsRandomly(void *bufferToFill, size_t sizeInBytes)
Fills a block of memory with random values.
bool nextBool() noexcept
Returns the next random boolean value.
void setSeedRandomly()
Reseeds this generator using a value generated from various semi-random system properties like the cu...
void combineSeed(int64 seedValue) noexcept
Merges this object's seed with another value.
int nextInt() noexcept
Returns the next random 32 bit integer.
~Random() noexcept
Destructor.
int64 nextInt64() noexcept
Returns the next 64-bit random number.
void setSeed(int64 newSeed) noexcept
Resets this Random object to a given seed value.
double nextDouble() noexcept
Returns the next random floating-point number.
BigInteger nextLargeNumber(const BigInteger &maximumValue)
Returns a BigInteger containing a random number.
static Random & getSystemRandom() noexcept
The overhead of creating a new Random object is fairly small, but if you want to avoid it,...
static int64 getHighResolutionTicks() noexcept
Returns the current high-resolution counter's tick-count.
static int64 currentTimeMillis() noexcept
Returns the current system time.
static int64 getHighResolutionTicksPerSecond() noexcept
Returns the resolution of the high-resolution counter in ticks per second.
static uint32 getMillisecondCounter() noexcept
Returns the number of millisecs since a fixed event (usually system startup).
This is a base class for classes that perform a unit test.