Random Classes

About

The MAXON API 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;
}
Py_ssize_t i
Definition: abstract.h:645
Py_ssize_t count
Definition: abstract.h:640
Definition: basearray.h:412
ResultMem EnsureCapacity(Int requestedCapacity, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY)
Definition: basearray.h:1480
MAXON_ATTRIBUTE_FORCE_INLINE ResultRef< T > Append(ARG &&x)
Definition: basearray.h:677
Definition: lib_math.h:19
FLOAT Get01()
Returns the next random value in the range of [0..1].
int32_t Int32
32 bit signed integer datatype.
Definition: apibase.h:176
float Float32
32 bit floating point value (float)
Definition: apibase.h:182
#define iferr_return
Definition: resultbase.h:1519

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);
}
ResultMem Resize(Int newCnt, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::DEFAULT)
Definition: basearray.h:1369
Definition: baseref.h:62
static MAXON_METHOD SecureRandomProvider GetDefaultProvider()
static MAXON_METHOD Bool GetRandomNumber(SecureRandomProvider provider, const Block< Byte > &buffer)
unsigned char UChar
unsigned 8 bit character
Definition: apibase.h:185
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:176

Further Reading