Add Random::nextBlob

This commit is contained in:
Vinnie Falco
2013-07-17 21:11:37 -07:00
parent 25f1a729ce
commit b2e764bf21
2 changed files with 21 additions and 0 deletions

View File

@@ -98,6 +98,23 @@ double Random::nextDouble() noexcept
return static_cast <uint32> (nextInt()) / (double) 0xffffffff;
}
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);
}
}
BigInteger Random::nextLargeNumber (const BigInteger& maximumValue)
{
BigInteger n;

View File

@@ -89,6 +89,10 @@ public:
*/
bool nextBool() noexcept;
/** Fills a piece of memory with random data.
*/
void nextBlob (void* buffer, size_t bytes);
/** Returns a BigInteger containing a random number.
@returns a random value in the range 0 to (maximumValue - 1).