Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/scottchiefbaker/simple-prng

Simple C++ implementations for popular PRNGs
https://github.com/scottchiefbaker/simple-prng

Last synced: 11 days ago
JSON representation

Simple C++ implementations for popular PRNGs

Awesome Lists containing this project

README

        

# simple-prng

Simple C++ implementations for popular Pseudo Random Number Generators

## Usage

```c++
#include
#include
#include

#include "pcg32.cpp"

int main(int argc, char *argv[]) {
pcg32 prng;

// Seed the PRNG
uint64_t seeds[2] = { 38424, 84924 };
prng.seed(seeds);

// Warm up the PRNG
for (int i = 0; i < 1024; i++) {
prng.rand();
}

// 32 bit randoms
for (int i = 0; i < 5; i++) { printf("%llu\n", prng.rand()); }

// 64 bit randoms
for (int i = 0; i < 5; i++) { printf("%llu\n", prng.rand64()); }
}
```

## Methods

`void prng.seed(uint64_t seeds[x])` seed the PRNG with 1 - 4 seeds

`uint32_t prng.rand()` fetch a random 32bit integer

`uint64_t prng.rand64()` fetch a random 64bit integer

## Available PRNGs

* PCG32 - `pcg32.cpp`
* SplitMix64 - `splitmix64.cpp`
* xoroshiro128+ - `xoroshiro128plus.cpp`
* xoshiro256** - `xoshiro256starstar.cpp`