← comparison · doc/random.md

Random numbers generation

Jngen provides a class Random whose behavior is similar to rnd from testlib.h. E.g. you may write rnd.next(100), rnd.next("[a-z]{%d}", n), and so on. Most of interaction with Random happens via its global instance of Random called rnd.

Default initialized Random is seeded with some hardware-generated random value, so subsequent executions of the program will produce different tests. This may be useful for local stress-testing, for example. If you want to fix the seed, use registerGen(argc, argv) at the beginning of your main.

Generation

uint32_t next()

uint64_t next64()

double nextf()

int next(int n) // also for long long, size_t, double

int next(int l, int r) // also for long long, size_t, double

int wnext(int n, int w) // also for long long, size_t, double

int wnext(int l, int r, int w) // also for long long, size_t, double

std::string next(const std::string& pattern)

std::string next(const std::string& pattern, ...)

template<typename T, typename ...Args>
tnext(Args... args)

std::pair<int, int> nextp(int n, [RandomPairTraits])

std::pair<int, int> nextp(int l, int r, [RandomPairTraits])

template<typename Iterator>
Iterator::value_type choice(Iterator begin, Iterator end)

template<typename Container>
Container::value_type choice(const Container& container)

template<typename N>
size_t nextByDistribution(const std::vector<N>& distribution)

Seeding

void seed(uint32_t seed)

void seed(const std::vector<uint32_t>& seed)

Related free functions

void registerGen(int argc, char* argv[], [int version])