6#ifndef CHEBYSHEV_RANDOM_H
7#define CHEBYSHEV_RANDOM_H
15#include "../core/common.h"
76 inline long double uniform(
long double a,
long double b) {
79 return u * (b - a) + a;
90 template<
typename Vector>
93 for (
int i = 0;
i <
x.size(); ++
i)
106 template<
typename Vector>
110 throw std::runtime_error(
111 "Vector and domain size mismatch in chebyshev::uniform"
115 for (
int i = 0;
i <
x.size(); ++
i)
127 inline long double gaussian(
long double m,
long double s) {
129 const long double x =
uniform(0.0, 1.0);
130 const long double y =
uniform(0.0, 1.0);
132 const long double v = std::sqrt(-2 * std::log(
x));
133 const long double u =
v * std::cos(2 *
PI_CONST *
y);
145 inline std::string
string(
size_t length) {
150 for (
unsigned int i = 0;
i < length; ++
i)
167 throw std::runtime_error(
168 "alphabet in chebyshev::random::string cannot be empty."
175 for (
unsigned int i = 0;
i < length; ++
i)
192 throw std::runtime_error(
193 "alphabet in chebyshev::random::string cannot be empty."
200 for (
unsigned int i = 0;
i < length; ++
i)
217 throw std::runtime_error(
218 "alphabet in chebyshev::random::string cannot be empty."
225 for (
unsigned int i = 0;
i < length; ++
i)
299 std::lock_guard<std::mutex>
lock(rndMutex);
context.
Definition random.h:240
random_context & operator=(const random_context &other)
Custom assignment operator to avoid copying std::mutex.
Definition random.h:287
void terminate()
Terminate the random module (currently empty).
Definition random.h:270
random_context(uint64_t seed=0)
Initialize the random module with the given seed.
Definition random.h:274
random_settings settings
Settings for the random context.
Definition random.h:252
random_source get_rnd()
Instantiate a new random source, automatically seeded with a new random seed.
Definition random.h:297
void setup(uint64_t seed=0)
Initialize the random module with the given seed.
Definition random.h:257
random_context(const random_context &other)
Custom copy constructor to avoid copying std::mutex.
Definition random.h:279
General namespace of the framework.
Definition benchmark.h:22
constexpr FloatType get_nan()
Get a quiet NaN of the specified floating point type.
Definition common.h:65
const long double PI_CONST
The Pi mathematical constant.
Definition common.h:71
std::mt19937 random_engine
Define the CH_CUSTOM_RND macro and a type random_engine to use a custom random number generator.
Definition random.h:24
Settings for the random module.
Definition random.h:236
A source of pseudorandom numbers.
Definition random.h:39
uint64_t get_seed()
Get the seed used to generate the random source.
Definition random.h:59
random_source(uint64_t seed)
Construct a random engine with the given seed.
Definition random.h:52
std::string string(size_t length, std::vector< char > alphabet)
Generate a random string made of the elements of the given alphabet.
Definition random.h:189
long double uniform(long double a, long double b)
Generate a uniformly distributed random number.
Definition random.h:76
std::string string(size_t length, std::string alphabet)
Generate a random string made of the elements of the given alphabet.
Definition random.h:164
long double gaussian(long double m, long double s)
Generate a Gaussian distributed random number.
Definition random.h:127
Vector & uniform(Vector &x, const std::vector< prec::interval > intervals)
Fill an already allocated vector with uniformly distributed numbers over different intervals.
Definition random.h:107
std::string string(size_t length)
Generate a random string made of human-readable ASCII characters.
Definition random.h:145
uint64_t natural()
Generate a random natural number.
Definition random.h:65
std::vector< T > string(size_t length, std::vector< T > alphabet)
Generate a random string made of the elements of the given alphabet, of arbitrary type.
Definition random.h:214
Vector & uniform(Vector &x, long double a, long double b)
Fill an already allocated vector with uniformly distributed numbers over the same interval.
Definition random.h:91