6#ifndef CHEBYSHEV_RANDOM_H
7#define CHEBYSHEV_RANDOM_H
15#include "../core/common.h"
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)
132 const real_t v = std::sqrt(-2 * std::log(
x));
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
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:236
A source of pseudorandom numbers.
Definition random.h:39
real_t gaussian(real_t m, real_t s)
Generate a Gaussian distributed random number.
Definition random.h:127
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:91
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
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
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
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:214