Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/depermitto/randshow
Header-only compendium of RNGs for C++
https://github.com/depermitto/randshow
cpp cpp11 cpp11-library header-only library random-number-generators
Last synced: about 1 month ago
JSON representation
Header-only compendium of RNGs for C++
- Host: GitHub
- URL: https://github.com/depermitto/randshow
- Owner: Depermitto
- License: mit
- Created: 2023-12-17T11:54:26.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-21T15:44:54.000Z (5 months ago)
- Last Synced: 2024-11-22T04:42:11.544Z (about 1 month ago)
- Topics: cpp, cpp11, cpp11-library, header-only, library, random-number-generators
- Language: C++
- Homepage:
- Size: 39.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Header-only library with many RNGs for **C++**
> Quality tested using [PractRand](https://pracrand.sourceforge.net/)
# Capabilities
Randshow aims to be smoother in use and 'more random' that engines found in the _\_ header of C++11. It ensures compatibility with [`UniformRandomBitGenerator`](https://en.cppreference.com/w/cpp/named_req/UniformRandomBitGenerator) and C++11 _\_ distributions.
# Usage
Download the contents of the _include_ directory and include desired headers in your code.
## Engines
> ****
- [PCG](https://www.pcg-random.org/) with 64-bit state and 32-bit output as well as a variant with 128-bit state and 64-bit output.
- [Xoshiro256++](https://prng.di.unimi.it/)
- [SplitMix64](https://rosettacode.org/wiki/Pseudo-random_numbers/Splitmix64#bodyContent)
- [LCG](https://en.wikipedia.org/wiki/Linear_congruential_generator?useskin=vector)## Distributions
> ****
- [Zipf Distribution](https://en.wikipedia.org/wiki/Zipf%27s_law?useskin=vector)
- [Benford's Distribution](https://en.wikipedia.org/wiki/Benford%27s_law?useskin=vector)## Examples
```C++
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
``````C++
// Create a histogram in Poisson distribution
randshow::PCG32 rng{};
std::unordered_map 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