Random Classes

About

The MAXON API ALIASES provides pseudo random number generators for trivial purposes and cryptographic applications.

Random

maxon::LinearCongruentialRandom is a standard pseudo random number generator that can be initialized with a seed value:

// This example fills an array with pseudo random numbers float values.
// prepare array
// init pseudo random generator
random.Init(123);
// fill array with random float values
for (maxon::Int32 i = 0; i < count; ++i)
{
const maxon::Float32 randomValue = random.Get01();
values.Append(randomValue) iferr_return;
}

SecureRandom

maxon::SecureRandom is a cryptographically secure pseudo-random number generator. It is typically used in the context of encrypting data. See Cryptography

maxon::SecureRandom provides these static functions:

// This example fills an array with cryptographically secure random data.
// prepare array
values.Resize(100) iferr_return;
// fill array with random data
// print random data
for (maxon::UChar& chr : values)
{
DiagnosticOutput("Random Data: @", chr);
}

Further Reading

maxon::SecureRandom::GetDefaultProvider
static MAXON_METHOD SecureRandomProvider GetDefaultProvider()
maxon::Float32
float Float32
32 bit floating point value (float)
Definition: apibase.h:180
maxon::BaseArray::Resize
ResultMem Resize(Int newCnt, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::DEFAULT)
Definition: basearray.h:1077
iferr_return
#define iferr_return
Definition: resultbase.h:1465
maxon::BaseArray
Definition: basearray.h:366
DiagnosticOutput
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:167
maxon::BaseArray::Append
MAXON_ATTRIBUTE_FORCE_INLINE ResultRef< T > Append()
Definition: basearray.h:569
maxon::Int32
int32_t Int32
32 bit signed integer datatype.
Definition: apibase.h:174
maxon::SecureRandom::GetRandomNumber
static MAXON_METHOD Bool GetRandomNumber(SecureRandomProvider provider, const Block< Byte > &buffer)
maxon::LinearCongruentialRandom
Definition: lib_math.h:18
maxon::LinearCongruentialRandom::Init
void Init(UInt32 seed)
maxon::UChar
unsigned char UChar
unsigned 8 bit character
Definition: apibase.h:183
maxon::LinearCongruentialRandom::Get01
FLOAT Get01()
Returns the next random value in the range of [0..1].
maxon::BaseArray::EnsureCapacity
ResultMem EnsureCapacity(Int requestedCapacity, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY)
Definition: basearray.h:1188
maxon::BaseRef
Definition: apibase.h:1527