6#ifndef CHEBYSHEV_RANDOM_H
7#define CHEBYSHEV_RANDOM_H
15#include "../core/common.h"
81 return u * (b - a) + a;
92 template<
typename Vector>
108 template<
typename Vector>
112 throw std::runtime_error(
113 "Vector and domain size mismatch in chebyshev::uniform"
117 for (
unsigned int i = 0;
i <
x.size(); ++
i)
134 const real_t v = std::sqrt(-2 * std::log(
x));
148 template<
typename Vector>
164 inline std::string
string(
size_t length) {
169 for (
unsigned int i = 0;
i < length; ++
i)
186 throw std::runtime_error(
187 "alphabet in chebyshev::random::string cannot be empty."
194 for (
unsigned int i = 0;
i < length; ++
i)
211 throw std::runtime_error(
212 "alphabet in chebyshev::random::string cannot be empty."
219 for (
unsigned int i = 0;
i < length; ++
i)
236 throw std::runtime_error(
237 "alphabet in chebyshev::random::string cannot be empty."
244 for (
unsigned int i = 0;
i < length; ++
i)
318 std::lock_guard<std::mutex>
lock(rndMutex);
context.
Definition random.h:259
random_context & operator=(const random_context &other)
Custom assignment operator to avoid copying std::mutex.
Definition random.h:306
void terminate()
Terminate the random module (currently empty).
Definition random.h:289
random_context(uint64_t seed=0)
Initialize the random module with the given seed.
Definition random.h:293
random_settings settings
Settings for the random context.
Definition random.h:271
random_source get_rnd()
Instantiate a new random source, automatically seeded with a new random seed.
Definition random.h:316
void setup(uint64_t seed=0)
Initialize the random module with the given seed.
Definition random.h:276
random_context(const random_context &other)
Custom copy constructor to avoid copying std::mutex.
Definition random.h:298
long double prec_t
Floating-point type of higher precision, used in computations, such as error estimation.
Definition common.h:42
double real_t
Floating-point type, used as default for function arguments.
Definition common.h:37
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 prec_t 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:255
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
Vector & uniform(Vector &x, real_t a, real_t b)
Fill an already allocated vector with uniformly distributed numbers over the same interval.
Definition random.h:93
Vector & gaussian(Vector &x, real_t mean, real_t sigma)
Fill an already allocated vector with Gaussian distributed numbers with the same mean and standard de...
Definition random.h:149
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:208
std::string string(size_t length, std::string alphabet)
Generate a random string made of the elements of the given alphabet.
Definition random.h:183
real_t gaussian(real_t mean, real_t sigma)
Generate a Gaussian distributed random number.
Definition random.h:129
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:109
std::string string(size_t length)
Generate a random string made of human-readable ASCII characters.
Definition random.h:164
real_t uniform(real_t a, real_t b)
Generate a uniformly distributed random number.
Definition random.h:76
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:233