Browse Source

Added another Random::fillBitsRandomly method.

tags/2021-05-28
jules 12 years ago
parent
commit
3e9f20da8f
2 changed files with 17 additions and 0 deletions
  1. +14
    -0
      modules/juce_core/maths/juce_Random.cpp
  2. +3
    -0
      modules/juce_core/maths/juce_Random.h

+ 14
- 0
modules/juce_core/maths/juce_Random.cpp View File

@@ -116,6 +116,20 @@ BigInteger Random::nextLargeNumber (const BigInteger& maximumValue)
return n;
}
void Random::fillBitsRandomly (void* const buffer, size_t bytes)
{
int* d = static_cast<int*> (buffer);
for (; bytes >= sizeof (int); bytes -= sizeof (int))
*d++ = nextInt();
if (bytes > 0)
{
const int lastBytes = nextInt();
memcpy (d, &lastBytes, bytes);
}
}
void Random::fillBitsRandomly (BigInteger& arrayToChange, int startBit, int numBits)
{
arrayToChange.setBit (startBit + numBits - 1, true); // to force the array to pre-allocate space


+ 3
- 0
modules/juce_core/maths/juce_Random.h View File

@@ -100,6 +100,9 @@ public:
*/
BigInteger nextLargeNumber (const BigInteger& maximumValue);
/** Fills a block of memory with random values. */
void fillBitsRandomly (void* bufferToFill, size_t sizeInBytes);
/** Sets a range of bits in a BigInteger to random values. */
void fillBitsRandomly (BigInteger& arrayToChange, int startBit, int numBits);


Loading…
Cancel
Save