Aller au contenu
Bienvenue sur la nouvelle documentation de CppUtils !

Deterministic, constexpr-compatible pseudo-random number generator (SplitMix64).

Provides reproducible pseudo-random generation suitable for unit tests, fuzz testing, and property-based verification. Generates identical sequences across platforms for a given seed.

static constexpr constexpr auto defaultSeed = 0x123456789ABCDEF0ULL;

Default 64-bit seed used for deterministic pseudo-random initialization.

explicit constexpr DeterministicRandomEngine::DeterministicRandomEngine(std::uint64_t seed = defaultSeed) noexcept;

Constructs a deterministic random engine with a given 64-bit seed.

ParamètreDescription
seedInitial seed (defaults to defaultSeed).
[[nodiscard]] constexpr auto DeterministicRandomEngine::seed() const noexcept -> std::uint64_t;

Returns the initial seed configured for this engine.

Retourne : 64-bit unsigned integer seed.

constexpr auto DeterministicRandomEngine::nextUint64() noexcept -> std::uint64_t;

Advances the generator state and produces the next raw 64-bit pseudo-random integer.

Retourne : Next pseudo-random std::uint64_t.

template <class Type>
constexpr auto DeterministicRandomEngine::random(Type minimum, Type maximum) noexcept -> Type;

Generates a pseudo-random value within the specified range [minimum, maximum].

Deduce the type automatically from parameters or specify it explicitly. Supports integral types, floating-point types, and booleans.

Paramètre templateDescription
TypeArithmetic or boolean type.
ParamètreDescription
minimumLower bound (inclusive).
maximumUpper bound (inclusive).

Retourne : Random value within [minimum, maximum].

template <class Type>
constexpr auto DeterministicRandomEngine::random() noexcept -> Type;

Generates a pseudo-random value of the requested type covering its standard range.

For integral types, covers [std::numeric_limits<Type>::min(), std::numeric_limits<Type>::max()]. For floating-point types, covers [0.0, 1.0]. For bool, returns true or false with a balanced 50% distribution.

Paramètre templateDescription
TypeTarget arithmetic or boolean type.

Retourne : Random value of type Type.

template <std::floating_point Float>
constexpr auto DeterministicRandomEngine::randomFloat(Float minimum = static_cast<Float>(0.0), Float maximum = static_cast<Float>(1.0)) noexcept -> Float;

Generates a floating-point number in [minimum, maximum] (defaults: 0.0 to 1.0).

Paramètre templateDescription
FloatFloating-point type.
ParamètreDescription
minimumLower bound (inclusive).
maximumUpper bound (inclusive).

Retourne : Random floating-point value.

constexpr auto DeterministicRandomEngine::randomSize(std::size_t minimum, std::size_t maximum) noexcept -> std::size_t;

Generates a pseudo-random size within the specified bounds.

ParamètreDescription
minimumLower bound (inclusive).
maximumUpper bound (inclusive).

Retourne : Random std::size_t in [minimum, maximum].

constexpr auto DeterministicRandomEngine::randomSize(std::size_t maximum) noexcept -> std::size_t;

Generates a pseudo-random size between 0 and maximum (inclusive).

ParamètreDescription
maximumUpper bound (inclusive).

Retourne : Random std::size_t in [0, maximum].

constexpr auto DeterministicRandomEngine::randomSize() noexcept -> std::size_t;

Generates a pseudo-random size bounded by PTRDIFF_MAX.

The generated size is bounded within [0, std::numeric_limits<std::ptrdiff_t>::max()] (PTRDIFF_MAX) instead of SIZE_MAX, ensuring that the size never exceeds the maximum legal contiguous object size in C++, thereby preserving the validity of pointer arithmetic ([expr.add#5]) during memory allocation and container stress testing.

Voir aussi : Limitation de la plage de valeurs et borne PTRDIFF_MAX

Retourne : Random std::size_t in [0, PTRDIFF_MAX].

constexpr auto DeterministicRandomEngine::randomString( std::size_t minimumLength = 0uz, std::size_t maximumLength = 32uz, std::string_view alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_ -") -> std::string;

Generates a pseudo-random string of variable length composed of characters from the given alphabet.

ParamètreDescription
minimumLengthMinimum number of characters.
maximumLengthMaximum number of characters.
alphabetView of available characters to sample from.

Retourne : Randomly generated std::string.

constexpr auto DeterministicRandomEngine::randomBytes(std::size_t count) -> std::vector<std::byte>;

Allocates and fills a vector of bytes with pseudo-random data.

ParamètreDescription
countNumber of bytes to generate.

Retourne : Vector of random bytes.

template <std::ranges::random_access_range Range>
constexpr auto DeterministicRandomEngine::pickOne(const Range& collection) -> const auto&;

Picks a pseudo-random element by const reference from a random access range.

Paramètre templateDescription
RangeRange satisfying std::ranges::random_access_range.
ParamètreDescription
collectionCollection to pick an element from.

Retourne : Const reference to the randomly selected element.