6 #ifndef CHEBYSHEV_RANDOM_H
7 #define CHEBYSHEV_RANDOM_H
10 #include "../prec/interval.h"
31 inline void setup(uint64_t seed = 0) {
53 inline long double uniform(
long double a,
long double b) {
54 return (rand() / (
long double) RAND_MAX) * (b - a) + a;
64 template<
typename Vector>
65 inline Vector&
sample_uniform(Vector& x,
const std::vector<prec::interval> intervals) {
67 if(x.size() != intervals.size())
68 throw std::runtime_error(
69 "Vector and domain size mismatch in chebyshev::sample_uniform");
71 for (
int i = 0; i < x.size(); ++i)
72 x[i] =
uniform(intervals[i].a, intervals[i].b);
89 for (
unsigned int i = 0; i < length; ++i)
90 str[i] =
'!' + (
char) (
natural() % 95);
106 throw std::runtime_error(
"alphabet in chebyshev::random::string cannot be empty.");
111 for (
unsigned int i = 0; i < length; ++i)
112 str[i] = alphabet[
natural() % alphabet.size()];
128 throw std::runtime_error(
"alphabet in chebyshev::random::string cannot be empty.");
133 for (
unsigned int i = 0; i < length; ++i)
134 str[i] = alphabet[
natural() % alphabet.size()];
147 inline std::vector<T>
string(
size_t length, std::vector<T> alphabet) {
150 throw std::runtime_error(
"alphabet in chebyshev::random::string cannot be empty.");
155 for (
unsigned int i = 0; i < length; ++i)
156 str[i] = alphabet[
natural() % alphabet.size()];
std::string string(size_t length)
Generate a random string made of human-readable ASCII characters.
Definition: random.h:84
uint64_t natural()
Generate a random natural number.
Definition: random.h:42
long double uniform(long double a, long double b)
Generate a uniformly distributed random number.
Definition: random.h:53
void setup(uint64_t seed=0)
Initialize the random module.
Definition: random.h:31
Vector & sample_uniform(Vector &x, const std::vector< prec::interval > intervals)
Fill an already allocated vector with uniformly distributed numbers over different intervals.
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:147
General namespace of the framework.
Definition: benchmark_structures.h:16
uint64_t seed
The seed for random number generation.
Definition: random.h:25