Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/scottchiefbaker/simple-prng
- Owner: scottchiefbaker
- License: mit
- Created: 2024-10-23T01:49:03.000Z (13 days ago)
- Default Branch: main
- Last Pushed: 2024-10-23T21:19:47.000Z (13 days ago)
- Last Synced: 2024-10-24T09:05:22.401Z (12 days ago)
- Language: C++
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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`