Skip to content

Depermitto/randshow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Header-only library with many RNGs for C++

Quality tested using PractRand

Capabilities

Randshow aims to be smoother in use and 'more random' that engines found in the <random> header of C++11. It ensures compatibility with UniformRandomBitGenerator and C++11 <random> distributions.

Usage

Download the contents of the include directory and include desired headers in your code.

Engines

<randshow/engines.hpp>

Distributions

<randshow/distributions.hpp>

Examples

randshow::PCG32 rng(17)                 // Custom seed
uint32_t num = rng.Next()               // Random 32-bit unsigned integer
uint32_t num_4_17 = rng.Next(4, 17);    // Equivalent to creating a new std::uniform_int_distribution
double_t num_0_1 = rng.NextReal();      // Random number in (0.0, 1.0) range
// Create a histogram in Poisson distribution
randshow::PCG32 rng{};
std::unordered_map<int, int> counter{};
std::poisson_distribution<> dist{10};

for (int n = 1000; n--;) {
    counter[dist(rng)] += 1;
}

for (size_t i = counter.size(); i--;) {
    std::string count(counter[i], '*');
    std::cout << i << ": " << count << "\n";
}

License

Licensed under the MIT license