Need Random::nextBlob ()


#1
/** Fill a piece of memory with random bytes.
*/
void Random::nextBlob (void* buffer, size_t bytes)
{
    int const remainder = bytes % sizeof (int64);

    {
        int64* dest = static_cast <int64*> (buffer);
        for (int i = bytes / sizeof (int64); i > 0; --i)
            *dest++ = nextInt64 ();
        buffer = dest;
    }

    {
        int64 const val = nextInt64 ();
        memcpy (buffer, &val, remainder);
    }
}

This is super handy for unit tests!


#2

Good call - I’ll add that! Though my naming preference would be to call it “fillBitsRandomly” to match the other method that does the same job for BigIntegers.