random¶
random_uniform function (generic::random_uniform)¶
template <f_class T, size_t N>
vec<T, N> random_uniform(random_state &state)
Generates a vector of uniformly distributed floating-point numbers in [0.0, 1.0).
This is derived by generating mantissas in [1.0, 2.0) and subtracting 1.0.
Template param T Floating-point type (f32 or f64).
Template param N Number of random floats to generate.
Param state Reference to the random number generator state.
Returns Vector of N floats in the range [0.0, 1.0).
random_range function (generic::random_range)¶
template <size_t N, f_class T>
vec<T, N> random_range(random_state &state, T min, T max)
Generates random values uniformly distributed in the range [min, max) for floating-point types.
Template param N Number of values to generate.
Template param T Floating-point type.
Param state Reference to the random number generator state.
Param min Lower bound of range.
Param max Upper bound of range.
Returns Vector of N values in the range [min, max).
template <size_t N, not_f_class T>
vec<T, N> random_range(random_state &state, T min, T max)
Generates random values uniformly distributed in the range [min, max) for integral types.
Uses integer scaling and rounding for range generation.
Template param N Number of values to generate.
Template param T Integral type.
Param state Reference to the random number generator state.
Param min Lower bound of range.
Param max Upper bound of range.
Returns Vector of N values in the range [min, max).
random_normal function (generic::random_normal)¶
template <size_t N, typename T>
vec<T, N> random_normal(random_state &state, T mu, T sigma)
Generates N normally distributed (Gaussian) random values using Box-Muller transform.
Uses 2x uniform samples to generate normal values, rounded to the nearest power-of-two vector length.
Template param N Number of normal values to generate.
Template param T Floating-point type.
Param state Reference to the random number generator state.
Param mu Mean of the distribution.
Param sigma Standard deviation of the distribution.
Returns Vector of N values from N(mu, sigma^2).
expression_random_uniform class (generic::expression_random_uniform)¶
template <typename T, index_t Dims, bool Reference = false>
expression_random_uniform
expression_random_range class (generic::expression_random_range)¶
template <typename T, index_t Dims, bool Reference = false>
expression_random_range
expression_random_normal class (generic::expression_random_normal)¶
template <typename T, index_t Dims, bool Reference = false>
expression_random_normal
gen_random_uniform function (generic::gen_random_uniform)¶
template <typename T, index_t Dims = 1>
expression_random_uniform<T, Dims>
gen_random_uniform(const random_state &state)
Returns expression that produces uniform pseudorandom values using a copied state.
template <typename T, index_t Dims = 1>
expression_random_range<T, Dims, true> gen_random_uniform(
    std::reference_wrapper<random_state> state)
Returns expression that produces uniform pseudorandom values using a referenced state. Use std::ref(gen) to use this overload.
template <typename T, index_t Dims = 1>
expression_random_range<T, Dims> gen_random_uniform()
Returns expression that produces uniform pseudorandom values using cycle counter entropy.
gen_random_range function (generic::gen_random_range)¶
template <typename T, index_t Dims = 1>
expression_random_range<T, Dims>
gen_random_range(const random_state &state, T min, T max)
Returns expression that produces random values in [min, max) using a copied state.
template <typename T, index_t Dims = 1>
expression_random_range<T, Dims, true>
gen_random_range(std::reference_wrapper<random_state> state,
                 T min, T max)
Returns expression that produces random values in [min, max) using a referenced state. Use std::ref(gen) to use this overload.
template <typename T, index_t Dims = 1>
expression_random_range<T, Dims> gen_random_range(T min,
                                                  T max)
Returns expression that produces random values in [min, max) using cycle counter entropy
gen_random_normal function (generic::gen_random_normal)¶
template <typename T, index_t Dims = 1>
expression_random_normal<T, Dims>
gen_random_normal(const random_state &state, T sigma = 1,
                  T mu = 0)
Returns expression that produces normally distributed values using a copied state.
template <typename T, index_t Dims = 1>
expression_random_normal<T, Dims, true> gen_random_normal(
    std::reference_wrapper<random_state> state, T sigma = 1,
    T mu = 0)
Returns expression that produces normally distributed values using a referenced state.
template <typename T, index_t Dims = 1>
expression_random_normal<T, Dims>
gen_random_normal(T sigma = 1, T mu = 0)
Returns expression that produces normally distributed values using cycle counter entropy.
seed_from_rdtsc_t class¶
seed_from_rdtsc_t
random_state class¶
random_state
random_next function (generic::random_next)¶
void random_next(random_state &state)
Advances the internal state of the pseudo-random number generator.
This function uses a SIMD-optimized linear congruential method with distinct
multiplier and adder constants for each 32-bit lane. The resulting values are
further randomized using a byte-wise rotate operation.
Param state Reference to the internal random number generator state to update.
random_init function (generic::random_init)¶
random_state random_init()
Initializes the random number generator state using the CPU cycle counter.
This variant seeds the generator using the result of KFR_builtin_readcyclecounter(),
ensuring variability across executions. It is only available when
KFR_DISABLE_READCYCLECOUNTER is not defined.
Returns A new random_state initialized with cycle counter entropy.
random_state random_init(u32 x0, u32 x1, u32 x2, u32 x3)
Initializes the random number generator with four 32-bit seed values.
This overload allows precise seeding of the internal 128-bit state using four
32-bit unsigned integers.
Param x0 First 32-bit seed value.
Param x1 Second 32-bit seed value.
Param x2 Third 32-bit seed value.
Param x3 Fourth 32-bit seed value.
Returns A new random_state initialized with the provided seeds.
random_state random_init(u64 x0, u64 x1)
Initializes the random number generator with two 64-bit seed values.
This overload combines two 64-bit unsigned integers into four 32-bit lanes
for initializing the internal 128-bit state.
Param x0 First 64-bit seed value.
Param x1 Second 64-bit seed value.
Returns A new random_state initialized with the provided seeds.
random_bits function (generic::random_bits)¶
template <size_t N>
  requires(N <= sizeof(random_state))
vec<u8, N> random_bits(random_state &state)
Generates up to 16 bytes of random data.
For output sizes less than or equal to 16 bytes (128 bits), this function returns
a random byte vector generated from a single call to random_next.
Template param N Number of random bytes to generate (N <= 16).
Param state Reference to the random number generator state.
Returns A vector of N random bytes.
Note This generator is stateless beyond its internal 128-bit state. It holds
no internal buffer, so each call to random_bits advances the state and
generates at least 128 bits of random data. To maintain deterministic
behavior across runs, always request the same size N in each usage scenario.
template <size_t N>
  requires(N > sizeof(random_state))
vec<u8, N> random_bits(random_state &state)
Generates more than 16 bytes of random data.
For output sizes greater than 16 bytes, this function recursively combines smaller
calls to random_bits to generate the requested number of random bytes.
Template param N Number of random bytes to generate (N > 16).
Param state Reference to the random number generator state.
Returns A vector of N random bytes.
Note This generator is stateless beyond its internal 128-bit state. It holds
no internal buffer, so each call to random_bits advances the state and
generates at least 128 bits of random data. To maintain deterministic
behavior across runs, always request the same size N in each usage scenario.
Auto-generated from sources, Revision , https://github.com/kfrlib/kfr/blob//include/kfr/