Simple C++ implementations for popular Pseudo Random Number Generators
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#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()); }
}
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
- PCG32 -
pcg32.cpp
- SplitMix64 -
splitmix64.cpp
- xoroshiro128+ -
xoroshiro128plus.cpp
- xoshiro256** -
xoshiro256starstar.cpp