Overview / Foundation

random

Fast random generation, deterministic from a seed, or secure through the operating system generator.

Always compiled: part of the core build.Include #include <ethereal/cpp/random/random.hpp>C layer

random.hpp

#include <ethereal/cpp/random/random.hpp>
enum

EGenerationMethod

Ethereal::Random#
C++
enum class EGenerationMethod : ETL_UINT8
{
    /// @brief    Uses standard C++ facilities such as std::uniform_int_distribution.
    ///            This is the most conventional and portable approach, but typically slower than optimized engine-based methods.
    ///
    eLegacySTL = 0,

    ///    @brief    Uses optimized @mt19937_64 generation combined with bitmask or multiply-high mapping techniques.
    ///            Designed for maximum throughput in performance-critical scenarios where cryptographic security is not required.
    ///
    eUltraFastBitMask,

    ///    @brief    Uses operating system CSPRNG facilities with thread-local buffering for both high security and high performance.
    ///            Intended for secure tokens, keys, and sensitive identifiers.
    ///
    eUltraFastOSSecurity
};

Defines the available random generation strategies.

function

GenerateFast

Ethereal::Random#
template< typename T > requires std::is_arithmetic_v< T > T GenerateFast( const T Min, const T Max ) noexcept;

Generates a fast pseudo-random value within the specified range.

Produces a uniformly distributed pseudo-random number between 'Min' and 'Max' using the thread-local fast random engine.

The function relies on a Mersenne Twister 64-bit engine (std::mt19937_64) stored as thread-local state. This avoids synchronization overhead and allows extremely fast random number generation suitable for high-performance scenarios such as simulations, procedural generation, or gameplay logic.

Internally delegates the generation logic to @GenerateFastImpl which applies optimized paths depending on the type category (integral or floating-point).

T
Arithmetic type of the generated value.
Min
Lower bound of the range (inclusive).
Max
Upper bound of the range.
Random value of type T within the specified range. @thread_safety Thread-safe. Each thread uses its own independent engine instance through thread-local storage. @performance Designed for extremely fast random generation. Avoids heavy distributions from the standard library and instead uses optimized bit operations and multiplication mapping.
function

noexcept

Ethereal::Random#
extern template int GenerateFast< int >( int, int ) noexcept;
function

noexcept

Ethereal::Random#
extern template unsigned int GenerateFast< unsigned int >( unsigned int, unsigned int ) noexcept;
function

noexcept

Ethereal::Random#
extern template long GenerateFast< long >( long, long ) noexcept;
function

noexcept

Ethereal::Random#
extern template long long GenerateFast< long long >( long long, long long ) noexcept;
function

noexcept

Ethereal::Random#
extern template unsigned long long GenerateFast< unsigned long long >( unsigned long long, unsigned long long ) noexcept;
function

noexcept

Ethereal::Random#
extern template float GenerateFast< float >( float, float ) noexcept;
function

noexcept

Ethereal::Random#
extern template double GenerateFast< double >( double, double ) noexcept;
function

GenerateDeterministic

Ethereal::Random#
template< typename T > requires std::is_arithmetic_v< T > T GenerateDeterministic( const ETL_UINT64 uSeed, const T Min, const T Max ) noexcept;

Generates a deterministic pseudo-random value using a fixed seed.

Produces a reproducible random value within the interval [Min, Max] by initializing a local std::mt19937_64 engine with the provided seed. Because the engine is recreated with the same seed on each call, identical inputs will always produce the same output. This behavior is useful for deterministic systems such as:

  • Procedural world generation;
  • Replay systems;
  • Deterministic simulations;
  • Testing and debugging.

The generation logic itself is delegated to @GenerateFastImpl, ensuring that the same optimized generation paths are used for both deterministic and non-deterministic random generation.

T
Arithmetic type of the generated value.
uSeed
Seed used to initialize the random engine.
Min
Lower bound of the range (inclusive).
Max
Upper bound of the range.
Deterministic pseudo-random value of type T within the specified range. @thread_safety Thread-safe. The engine is local to the function invocation. @performance Slightly slower than @GenerateFast due to engine construction and seeding on each call.
function

noexcept

Ethereal::Random#
extern template int GenerateDeterministic< int >( ETL_UINT64, int, int ) noexcept;
function

noexcept

Ethereal::Random#
extern template unsigned int GenerateDeterministic< unsigned int >( ETL_UINT64, unsigned int, unsigned int ) noexcept;
function

noexcept

Ethereal::Random#
extern template long GenerateDeterministic< long >( ETL_UINT64, long, long ) noexcept;
function

noexcept

Ethereal::Random#
extern template long long GenerateDeterministic< long long >( ETL_UINT64, long long, long long ) noexcept;
function

noexcept

Ethereal::Random#
extern template unsigned long long GenerateDeterministic< unsigned long long >( ETL_UINT64, unsigned long long, unsigned long long ) noexcept;
function

noexcept

Ethereal::Random#
extern template float GenerateDeterministic< float >( ETL_UINT64, float, float ) noexcept;
function

noexcept

Ethereal::Random#
extern template double GenerateDeterministic< double >( ETL_UINT64, double, double ) noexcept;
function

GenerateSecure

Ethereal::Random#
template< typename T > requires std::is_integral_v< T > T GenerateSecure( const T Min, const T Max ) noexcept;

Generates a secure random integer within the specified range.

Produces a uniformly distributed random integer between 'Min' and 'Max' using the operating system secure entropy source.

Unlike @GenerateFast, this function relies on a secure entropy provider backed by the operating system (for example:BCryptGenRandom on Windows, getrandom on Linux, or arc4random on macOS). Random bytes are fetched into a thread-local buffer and consumed as needed.

The implementation uses optimized range-mapping techniques to avoid modulo bias while maintaining high performance:

  • If the interval size is a power of two, a fast bit-mask operation is used.
  • Otherwise the random value is mapped into the target range using high-multiplication mapping (MulHi).

Depending on the size of the integer type, the function automatically selects a 32-bit or 64-bit mapping path.

This function is intended for situations where stronger randomness is required, such as:

  • Token generation;
  • Security identifiers;
  • Cryptographic nonces;
  • Session identifiers.
T
Integral type of the generated value.
Min
Lower bound of the range (inclusive).
Max
Upper bound of the range.
Secure random integer of type @T within the specified interval. @thread_safety Thread-safe. Secure random data is retrieved from a thread-local entropy buffer to avoid synchronization overhead. @performance Slower than @GenerateFast due to reliance on secure system entropy sources, but significantly faster than repeatedly invoking OS-level random APIs thanks to the internal TLS buffer.
function

noexcept

Ethereal::Random#
extern template int GenerateSecure< int >( int, int ) noexcept;
function

noexcept

Ethereal::Random#
extern template unsigned int GenerateSecure< unsigned int >( unsigned int, unsigned int ) noexcept;
function

noexcept

Ethereal::Random#
extern template long GenerateSecure< long >( long, long ) noexcept;
function

noexcept

Ethereal::Random#
extern template unsigned long GenerateSecure< unsigned long >( unsigned long, unsigned long ) noexcept;
function

noexcept

Ethereal::Random#
extern template long long GenerateSecure< long long >( long long, long long ) noexcept;
function

noexcept

Ethereal::Random#
extern template unsigned long long GenerateSecure< unsigned long long >( unsigned long long, unsigned long long ) noexcept;
function

GenerateFastBatch

Ethereal::Random#
template< typename T > requires std::is_arithmetic_v< T > void GenerateFastBatch( T * Out, const ETL_UINT64 Count, const T Min, const T Max ) noexcept;

Generates a batch of fast pseudo-random values.

Fills the output buffer with 'Count' pseudo-random values within the interval [Min, Max] using the thread-local fast random engine. This function uses a thread-local instance of @std::mt19937_64 to avoid synchronization overhead between threads. The generation logic is delegated to @GenerateBatchImpl which applies several performance optimizations such as loop unrolling and bias-free range mapping.

T
Arithmetic type of the generated values.
Out
Pointer to the destination buffer.
Count
Number of values to generate.
Min
Lower bound of the range (inclusive).
Max
Upper bound of the range. @thread_safety Thread-safe. Each thread operates on its own engine instance stored in thread-local storage. @performance Significantly faster than repeated calls to single-value generators due to vectorized-style batch processing and reduced branching.
function

noexcept

Ethereal::Random#
extern template void GenerateFastBatch< int >( int*, ETL_UINT64, int, int ) noexcept;
function

noexcept

Ethereal::Random#
extern template void GenerateFastBatch< unsigned int >( unsigned int*, ETL_UINT64, unsigned int, unsigned int ) noexcept;
function

noexcept

Ethereal::Random#
extern template void GenerateFastBatch< long >( long*, ETL_UINT64, long, long ) noexcept;
function

noexcept

Ethereal::Random#
extern template void GenerateFastBatch< unsigned long >( unsigned long*, ETL_UINT64, unsigned long, unsigned long ) noexcept;
function

noexcept

Ethereal::Random#
extern template void GenerateFastBatch< long long >( long long*, ETL_UINT64, long long, long long ) noexcept;
function

noexcept

Ethereal::Random#
extern template void GenerateFastBatch< unsigned long long >( unsigned long long*, ETL_UINT64, unsigned long long, unsigned long long ) noexcept;
function

noexcept

Ethereal::Random#
extern template void GenerateFastBatch< float >( float*, ETL_UINT64, float, float ) noexcept;
function

noexcept

Ethereal::Random#
extern template void GenerateFastBatch< double >( double*, ETL_UINT64, double, double ) noexcept;
function

GenerateDeterministicBatch

Ethereal::Random#
template< typename T > requires std::is_arithmetic_v< T > void GenerateDeterministicBatch( T * Out, const ETL_UINT64 Count, const ETL_UINT64 uSeed, const T Min, const T Max ) noexcept;

Generates a deterministic batch of pseudo-random values.

Fills the output buffer with 'Count' deterministic pseudo-random values within the interval [Min, Max]. A local @std::mt19937_64 engine is initialized using the provided seed, ensuring that identical inputs will always produce identical output sequences. This behavior is useful for deterministic systems such as:

  • Procedural generation.
  • Replay systems;
  • Simulations;
  • Testing and debugging.

The generation logic is delegated to @GenerateBatchImpl, ensuring identical statistical behavior compared to the fast batch generator.

T
Arithmetic type of the generated values.
Out
Pointer to the destination buffer.
Count
Number of values to generate.
uSeed
Seed used to initialize the deterministic engine.
Min
Lower bound of the range (inclusive).
Max
Upper bound of the range. @thread_safety Thread-safe. The random engine is local to the function call. @performance Slightly slower than @GenerateFastBatch due to engine initialization and seeding.
function

noexcept

Ethereal::Random#
extern template void GenerateDeterministicBatch< int >( int*, ETL_UINT64, ETL_UINT64, int, int ) noexcept;
function

noexcept

Ethereal::Random#
extern template void GenerateDeterministicBatch< unsigned int >( unsigned int*, ETL_UINT64, ETL_UINT64, unsigned int, unsigned int ) noexcept;
function

noexcept

Ethereal::Random#
extern template void GenerateDeterministicBatch< long >( long*, ETL_UINT64, ETL_UINT64, long, long ) noexcept;
function

noexcept

Ethereal::Random#
extern template void GenerateDeterministicBatch< unsigned long >( unsigned long*, ETL_UINT64, ETL_UINT64, unsigned long, unsigned long ) noexcept;
function

noexcept

Ethereal::Random#
extern template void GenerateDeterministicBatch< long long >( long long*, ETL_UINT64, ETL_UINT64, long long, long long ) noexcept;
function

noexcept

Ethereal::Random#
extern template void GenerateDeterministicBatch< unsigned long long >( unsigned long long*, ETL_UINT64, ETL_UINT64, unsigned long long, unsigned long long ) noexcept;
function

noexcept

Ethereal::Random#
extern template void GenerateDeterministicBatch< float >( float*, ETL_UINT64, ETL_UINT64, float, float ) noexcept;
function

noexcept

Ethereal::Random#
extern template void GenerateDeterministicBatch< double >( double*, ETL_UINT64, ETL_UINT64, double, double ) noexcept;
function

GenerateFastCString

Ethereal::Random#
void GenerateFastCString( char * OutBuffer, const std::size_t OutBufferLength, const bool bNullTerminateSyntax = true, const EGenerationMethod EMethod = EGenerationMethod::eLegacySTL, const char * sCharset = nullptr, const std::size_t sCharsetLength = 0 ) noexcept;

Generates a fast pseudo-random C-style string.

Fills the provided character buffer with randomly selected characters from the specified charset. The generation method can be selected through @EMethod, allowing different performance and entropy strategies. Supported generation modes:

  • eUltraFastOSSecurity -> Uses ultra-fast OS entropy syscalls to obtain random data.
  • eUltraFastBitMask -> Uses the thread-local MT19937-64 engine combined with optimized bit-mask mapping for extremely high performance.
  • eLegacySTL -> Uses std::uniform_int_distribution with the MT engine. This is slower but fully STL-compliant.

If the charset pointer is null or invalid, a default internal charset will be used automatically. The generated characters are written directly into the supplied buffer without dynamic allocation.

OutBuffer
Destination buffer receiving the generated string.
OutBufferLength
Total capacity of the output buffer.
bNullTerminateSyntax
If true, appends a '\0' terminator at the end.
EMethod
Random generation strategy to use.
sCharset
Optional custom character set.
sCharsetLength
Length of the provided charset. @note: Use a charset length that is a power of two to enable the fastest generation path. @thread_safety Thread-safe. Uses a thread-local random engine when the MT-based generator is selected. @performance Designed for extremely high throughput random string generation. The ultra-fast methods avoid expensive STL distributions and minimize branching.
function

GenerateDeterministicCString

Ethereal::Random#
void GenerateDeterministicCString( const ETL_UINT64 uSeed, char * OutBuffer, const std::size_t OutBufferLength, const bool bNullTerminateSyntax = true, const EGenerationMethod EMethod = EGenerationMethod::eLegacySTL, const char * sCharset = nullptr, const std::size_t sCharsetLength = 0 ) noexcept;

Generates a deterministic pseudo-random C-style string.

Fills the provided character buffer with characters selected from the given charset using a deterministic random engine initialized with the supplied seed. Identical inputs (seed, charset, and buffer size) will always produce identical output strings. This makes the function suitable for deterministic workflows such as:

  • Procedural generation;
  • Reproducible simulations;
  • Replay systems;
  • Testing environments.

If the charset pointer is null or invalid, a default internal charset will be used automatically. The generated characters are written directly into the supplied buffer without dynamic allocation.

uSeed
Seed used to initialize the deterministic engine.
OutBuffer
Destination buffer receiving the generated string.
OutBufferLength
Total capacity of the output buffer.
bNullTerminateSyntax
If true, appends a '\0' terminator at the end.
EMethod
Random generation strategy to use.
sCharset
Optional custom character set.
sCharsetLength
Length of the provided charset. @note: Use a charset length that is a power of two to enable the fastest generation path. @thread_safety Thread-safe. The random engine is local to the function call. @performance Slightly slower than @GenerateFastCString due to deterministic engine initialization.
function

GenerateSecureCString

Ethereal::Random#
void GenerateSecureCString( char * OutBuffer, const std::size_t OutBufferLength, const bool bNullTerminateSyntax = true, const EGenerationMethod EMethod = EGenerationMethod::eLegacySTL, const char * sCharset = nullptr, const std::size_t sCharsetLength = 0 ) noexcept;

Generates a cryptographically secure C-style random string.

Fills the provided character buffer with characters selected from the specified charset using a secure entropy source. The generation method can be selected through @EMethod, allowing different performance and entropy strategies. This function is recommended for generating:

  • Authentication tokens;
  • Session identifiers;
  • API keys;
  • Security nonces.

If the charset pointer is null or invalid, a default internal charset will be used automatically. The generated characters are written directly into the supplied buffer without dynamic allocation.

OutBuffer
Destination buffer receiving the generated string.
OutBufferLength
Total capacity of the output buffer.
bNullTerminateSyntax
If true, appends a '\0' terminator at the end.
EMethod
Random generation strategy to use.
sCharset
Optional custom character set.
sCharsetLength
Length of the provided charset. @note: Use a charset length that is a power of two to enable the fastest generation path. @thread_safety Thread-safe. Secure entropy sources and random devices are internally synchronized by the operating system. @performance Slower than fast generators due to reliance on secure entropy sources, but still optimized through buffered generation paths.
function

GenerateFastString

Ethereal::Random#
void GenerateFastString( std::string & StrOut, const std::size_t MaxLength, const EGenerationMethod EMethod = EGenerationMethod::eLegacySTL, const char * sCharset = nullptr, const std::size_t sCharsetLength = 0 ) noexcept;

Generates a fast pseudo-random string using @std::string.

Fills the provided std::string with randomly selected characters from the specified charset. The output string is resized to the requested length and written directly through its internal buffer for maximum performance. Supported generation modes:

  • eUltraFastOSSecurity -> Uses ultra-fast OS entropy syscalls to obtain random data.
  • eUltraFastBitMask -> Uses the thread-local MT19937-64 engine combined with optimized bit-mask mapping for extremely high performance.
  • eLegacySTL -> Uses std::uniform_int_distribution with the MT engine. This is slower but fully STL-compliant.

If the charset pointer is null or invalid, a default internal charset will be used automatically. The generated characters are written directly into the supplied string without dynamic allocation.

StrOut
Output string receiving the generated characters.
Length
Desired length of the generated string.
EMethod
Random generation strategy to use.
sCharset
Optional custom character set.
sCharsetLength
Length of the provided charset. @note: Use a charset length that is a power of two to enable the fastest generation path. @thread_safety Thread-safe. Uses a thread-local random engine for fast generation. @performance Highly optimized. Avoids dynamic growth and @push_back overhead by resizing the string once and writing directly to the internal buffer.
function

GenerateDeterministicString

Ethereal::Random#
void GenerateDeterministicString( const ETL_UINT64 uSeed, std::string & StrOut, const std::size_t Length, const EGenerationMethod EMethod = EGenerationMethod::eLegacySTL, const char * sCharset = nullptr, const std::size_t sCharsetLength = 0 ) noexcept;

Generates a deterministic pseudo-random string using @std::string.

Fills the provided @std::string with characters selected from the specified charset using a deterministic random generator seeded with the provided value. Identical inputs (seed, charset and length) will always produce identical strings. This makes the function useful for deterministic systems such as:

  • Procedural generation;
  • Replay systems;
  • Testing environments;
  • Deterministic simulations.

If the charset pointer is null or invalid, a default internal charset will be used automatically. The generated characters are written directly into the supplied string without dynamic allocation.

uSeed
Seed used to initialize the deterministic generator.
StrOut
Output string receiving the generated characters.
Length
Desired length of the generated string.
EMethod
Random generation strategy to use.
sCharset
Optional custom character set.
sCharsetLength
Length of the provided charset. @note: Use a charset length that is a power of two to enable the fastest generation path. @thread_safety Thread-safe. The random engine is local to the function call. @performance Slightly slower than GenerateFastString due to deterministic engine initialization.
function

GenerateSecureString

Ethereal::Random#
void GenerateSecureString( std::string & StrOut, const std::size_t Length, const EGenerationMethod EMethod = EGenerationMethod::eLegacySTL, const char * sCharset = nullptr, const std::size_t sCharsetLength = 0 ) noexcept;

Generates a cryptographically secure random string using std::string.

Fills the provided std::string with characters selected from the specified charset using secure entropy sources. The generation method can be selected through @EMethod, allowing different performance and entropy strategies. This function is recommended for generating:

  • Authentication tokens;
  • Session identifiers;
  • API keys;
  • Security nonces.

If the charset pointer is null or invalid, a default internal charset will be used automatically. The generated characters are written directly into the supplied string without dynamic allocation.

StrOut
Output string receiving the generated characters.
Length
Desired length of the generated string.
EMethod
Random generation strategy to use.
sCharset
Optional custom character set.
sCharsetLength
Length of the provided charset. @note: Use a charset length that is a power of two to enable the fastest generation path. @thread_safety Thread-safe. Secure entropy sources are internally synchronized by the operating system. @performance Slower than fast generators due to secure entropy usage, but still optimized through direct buffer writes.
function

GenerateNanoID

Ethereal::Random#
void GenerateNanoID( char * OutBuffer, const std::size_t OutBufferLength, const bool bNullTerminateSyntax = true ) noexcept;

Generates a NanoID-style random identifier (C-string version).

Fills the provided character buffer with a randomly generated identifier using the library default charset. The identifier follows the NanoID concept: short, URL-safe, and high-entropy. The function uses the thread-local fast random generator (@std::mt19937_64) combined with the ultra-fast character mapping routine to maximize generation throughput.

The output is written directly into the provided buffer without any dynamic allocation. If @bNullTerminateSyntax is enabled, the resulting identifier will be null-terminated.

OutBuffer
Destination buffer receiving the generated ID.
OutBufferLength
Total capacity of the output buffer.
bNullTerminateSyntax
If true, appends a '\0' terminator. @thread_safety Thread-safe. Uses a thread-local random engine. @performance Extremely fast. Uses optimized bit-mapping and direct buffer writes without STL distributions or dynamic allocations.
function

GenerateNanoID

Ethereal::Random#
void GenerateNanoID( std::string & StrOut, const std::size_t Length ) noexcept;

Generates a NanoID-style random identifier (@std::string version).

Produces a NanoID-style random identifier stored inside a @std::string. The output string is resized to the requested length and filled directly through its internal buffer. The identifier uses the library default charset and the ultra-fast @MT19937-64 random generator.

This implementation avoids @push_back and repeated allocations by resizing the string once and writing directly to the internal memory buffer.

StrOut
Output string receiving the generated identifier.
Length
Desired length of the identifier. @thread_safety Thread-safe. Uses a thread-local random engine. @performance Highly optimized for throughput. Performs a single allocation and writes directly into the string buffer.
function

GenerateUUIDv4

Ethereal::Random#
void GenerateUUIDv4( char * OutBuffer, const std::size_t OutBufferLength = 37, const bool bNullTerminateSyntax = true ) noexcept;

Generates a UUID version 4 (RFC 4122) identifier (C-string version).

Generates a 128-bit UUID using secure entropy obtained from the operating system. The resulting identifier follows the RFC 4122 specification for version 4 UUIDs (random-based). The function generates 16 random bytes, then adjusts specific bits to encode the required UUID metadata:

  • Version field (UUIDv4) -> Bits 12 to 15 are set to 0100.
  • Variant field (RFC4122) -> The two most significant bits of byte 8 are set to 10.

The final UUID is formatted as a canonical string representation: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

The output is written directly into the provided buffer without dynamic allocations.

OutBuffer
Destination buffer receiving the generated UUID.
OutBufferLength
Capacity of the output buffer. @note: Must be at least 36 characters (or 37 if null termination is enabled).
bNullTerminateSyntax
If true, appends a '\0' terminator. @thread_safety Thread-safe. Uses a thread-local secure entropy buffer. @performance Highly efficient. Generates random bytes in bulk and converts them directly to hexadecimal without intermediate allocations.
function

GenerateUUIDv4

Ethereal::Random#
void GenerateUUIDv4( std::string & StrOut ) noexcept;

Generates a UUID version 4 (RFC 4122) identifier (@std::string version).

Generates a 128-bit UUID using secure entropy obtained from the operating system. The resulting identifier follows the RFC 4122 specification for version 4 UUIDs (random-based). The function generates 16 random bytes, then adjusts specific bits to encode the required UUID metadata:

  • Version field (UUIDv4) -> Bits 12 to 15 are set to 0100.
  • Variant field (RFC4122) -> The two most significant bits of byte 8 are set to 10.

The final UUID is formatted as a canonical string representation: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

The string is resized once to the required length (36 characters) and written directly through its internal buffer to avoid additional allocations.

StrOut
Output string receiving the generated UUID. @thread_safety Thread-safe. Secure entropy is obtained from a thread-local randomness buffer. @performance Efficient implementation using direct buffer writes and pre-sized string storage.
function

GenerateTokenHex

Ethereal::Random#
void GenerateTokenHex( char * OutBuffer, const std::size_t OutBufferLength, const bool bNullTerminateSyntax = true ) noexcept;

Generates a secure hexadecimal token (C-string version).

Fills the provided buffer with a hexadecimal representation of cryptographically secure random bytes. Random bytes are generated in 64-bit blocks using the internal secure TLS entropy buffer. The function generates random bytes in 64-bit blocks for improved performance and converts them into hexadecimal characters.

Each byte produces two hexadecimal characters, meaning the output string length is twice the number of random bytes generated. The output is written directly into the provided buffer without dynamic allocations.

OutBuffer
Destination buffer receiving the generated token.
OutBufferLength
Total capacity of the output buffer.
bNullTerminateSyntax
If true, appends a '\0' terminator. @thread_safety Thread-safe. Uses a thread-local secure entropy buffer. @performance Optimized for high throughput by generating random values in 64-bit blocks and converting them directly to hexadecimal.
function

GenerateTokenHex

Ethereal::Random#
void GenerateTokenHex( std::string & StrOut, const std::size_t Bytes ) noexcept;

Generates a secure hexadecimal token (@std::string version).

Fills the provided @std::string with a hexadecimal representation of cryptographically secure random bytes. Random bytes are generated in 64-bit blocks using the internal secure TLS entropy buffer. The function generates random bytes in 64-bit blocks for improved performance and converts them into hexadecimal characters.

Each byte produces two hexadecimal characters, meaning the output string length is twice the number of random bytes generated. The string is resized once to its final size (two characters per random byte) and written directly through the internal buffer to avoid repeated allocations.

StrOut
Output string receiving the generated token.
Bytes
Number of random bytes to generate. @thread_safety Thread-safe. Uses a thread-local secure entropy buffer. @performance Highly efficient. Generates random data in 64-bit blocks and writes directly into the string buffer.
function

GenerateTokenBase64

Ethereal::Random#
void GenerateTokenBase64( char * OutBuffer, const std::size_t OutBufferLength, const bool bNullTerminateSyntax = true ) noexcept;

Generates a Base64 random token (C-string version).

Fills the provided buffer with a random token using the standard Base64 character. Random bytes are generated in 64-bit blocks using the internal secure TLS entropy buffer.

For performance, random data is generated in 64-bit blocks and converted directly into Base64 indices using bit masking. Each extracted byte is mapped to the Base64 alphabet through a fast lookup table.

The resulting string length is defined by the size of the output buffer. If null-termination is requested, the last byte is reserved for the '\0' character. The output is written directly into the provided buffer without dynamic allocations.

OutBuffer
Destination buffer receiving the generated token.
OutBufferLength
Total capacity of the output buffer.
bNullTerminateSyntax
If true, appends a '\0' terminator. @thread_safety Thread-safe. Uses a thread-local secure entropy buffer. @performance Highly optimized. Generates random values in 64-bit blocks and performs direct Base64 lookup without STL encoders.
function

GenerateTokenBase64

Ethereal::Random#
void GenerateTokenBase64( std::string & StrOut, const std::size_t Bytes ) noexcept;

Generates a Base64 random token (@std::string version).

Fills the provided @std::string with a random token using the standard Base64 character. Random bytes are generated in 64-bit blocks using the internal secure TLS entropy buffer.

For performance, random data is generated in 64-bit blocks and converted directly into Base64 indices using bit masking. Each extracted byte is mapped to the Base64 alphabet through a fast lookup table.

The output string is resized once to its final size and written directly through its internal buffer to avoid reallocations.

StrOut
Output string receiving the generated Base64 token.
Bytes
Number of secure random bytes used as entropy. @thread_safety Thread-safe. Random data is obtained from a thread-local secure entropy buffer. @performance Efficient implementation using block processing and direct buffer writes.
function

SecureBytes

Ethereal::Random#
void SecureBytes( std::span< std::uint8_t > OutBytes ) noexcept;

Fills a buffer with bytes from the operating system cryptographic generator.

BCryptGenRandom on Windows, getrandom on Linux, arc4random on macOS. It is the same source that feeds GenerateUUIDv4 and the token generators, now reachable directly: without it, code that needed N bytes of raw entropy had to request a text token and undo the formatting, or reimplement the per platform access.

OutBytes
Buffer to fill. An empty buffer is ignored.
Suitable for keys, nonces, seeds and identifiers. Do not use the fast generators for that.