TTS v3.0.0
The Tiny Test System
Loading...
Searching...
No Matches
Utilities

Functions

template<typename T>
tts::random_value (T mini, T maxi)
 Generates a random value between two bounds.
void tts::set_random_seed (std::uint64_t seed)
 Sets the seed for the internal PRNG to guarantee reproducibility.

Function Documentation

◆ random_value()

template<typename T>
T tts::random_value ( T mini,
T maxi )

#include <tts/tools/random.hpp>

Generates a random value between two bounds.

This function generates a random value of type T between the specified mini and maxi bounds using an uniform distribution for integral types and a log-uniform distribution for floating-point types.

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
TTS_CASE_TPL("Check tts::random_value", float, double, int)
<typename T>(tts::type<T>)
{
for(auto i = 0; i < 100000; ++i)
{
T val = tts::random_value(T(-10), T(+10));
TTS_EXPECT(val >= T(-10)) << val;
TTS_EXPECT(val <= T(+10)) << val;
}
};
Parameters
miniLower bound for the random value generation.
maxiUpper bound for the random value generation.
Returns
A random value of type T between mini and maxi.
See also
tts::randoms

◆ set_random_seed()

void tts::set_random_seed ( std::uint64_t seed)
inline

#include <tts/tools/random.hpp>

Sets the seed for the internal PRNG to guarantee reproducibility.

Parameters
seedThe 64-bit seed value to initialize the generator state.