Chebyshev
Unit testing for scientific software
Loading...
Searching...
No Matches
chebyshev::random::random_source Class Reference

A source of pseudorandom numbers. More...

#include <random.h>

Public Member Functions

 random_source (uint64_t seed)
 Construct a random engine with the given seed.
 
uint64_t get_seed ()
 Get the seed used to generate the random source.
 
uint64_t natural ()
 Generate a random natural number.
 
real_t uniform (real_t a, real_t b)
 Generate a uniformly distributed random number.
 
template<typename Vector >
Vectoruniform (Vector &x, real_t a, real_t b)
 Fill an already allocated vector with uniformly distributed numbers over the same interval.
 
template<typename Vector >
Vectoruniform (Vector &x, const std::vector< prec::interval > intervals)
 Fill an already allocated vector with uniformly distributed numbers over different intervals.
 
real_t gaussian (real_t m, real_t s)
 Generate a Gaussian distributed random number.
 
std::string string (size_t length)
 Generate a random string made of human-readable ASCII characters.
 
std::string string (size_t length, std::string alphabet)
 Generate a random string made of the elements of the given alphabet.
 
std::string string (size_t length, std::vector< char > alphabet)
 Generate a random string made of the elements of the given alphabet.
 
template<typename T >
std::vector< Tstring (size_t length, std::vector< T > alphabet)
 Generate a random string made of the elements of the given alphabet, of arbitrary type.
 

Detailed Description

A source of pseudorandom numbers.

Can be automatically generated from a random_context by using get_rnd().

Member Function Documentation

◆ gaussian()

real_t chebyshev::random::random_source::gaussian ( real_t  m,
real_t  s 
)
inline

Generate a Gaussian distributed random number.

Parameters
mThe mean of the distribution
sThe standard deviation of the distribution
Returns
A pseudorandom number Gaussian distributed.

◆ string() [1/4]

std::string chebyshev::random::random_source::string ( size_t  length)
inline

Generate a random string made of human-readable ASCII characters.

Parameters
lengthThe length of the string to generate
Returns
A string generated by choosing the elements of the alphabet with uniform probability.

◆ string() [2/4]

std::string chebyshev::random::random_source::string ( size_t  length,
std::string  alphabet 
)
inline

Generate a random string made of the elements of the given alphabet.

Parameters
lengthThe length of the string to generate
alphabetA string containing the elements of the alphabet.
Returns
A string generated by choosing the elements of the alphabet with uniform probability.

◆ string() [3/4]

std::string chebyshev::random::random_source::string ( size_t  length,
std::vector< char alphabet 
)
inline

Generate a random string made of the elements of the given alphabet.

Parameters
lengthThe length of the string to generate.
alphabetA vector containing the elements of the alphabet.
Returns
A string generated by choosing the elements of the alphabet with uniform probability.

◆ string() [4/4]

template<typename T >
std::vector< T > chebyshev::random::random_source::string ( size_t  length,
std::vector< T alphabet 
)
inline

Generate a random string made of the elements of the given alphabet, of arbitrary type.

Parameters
lengthThe length of the string to generate
Returns
A vector generated by choosing the elements of the alphabet with uniform probability.

◆ uniform() [1/3]

real_t chebyshev::random::random_source::uniform ( real_t  a,
real_t  b 
)
inline

Generate a uniformly distributed random number.

Parameters
aThe lower extreme of the interval
bThe upper extreme of the interval
Returns
A pseudorandom number uniformly distributed over (a, b).

◆ uniform() [2/3]

template<typename Vector >
Vector & chebyshev::random::random_source::uniform ( Vector x,
const std::vector< prec::interval intervals 
)
inline

Fill an already allocated vector with uniformly distributed numbers over different intervals.

Parameters
xThe already initialized vector to fill.
intervalsThe intervals to generate over.
Returns
A reference to the overwritten vector.

◆ uniform() [3/3]

template<typename Vector >
Vector & chebyshev::random::random_source::uniform ( Vector x,
real_t  a,
real_t  b 
)
inline

Fill an already allocated vector with uniformly distributed numbers over the same interval.

Parameters
xThe already initialized vector to fill.
aThe lower extreme of the interval
bThe upper extreme of the interval
Returns
A reference to the overwritten vector.

The documentation for this class was generated from the following file: