Skip to content

Instantly share code, notes, and snippets.

// badseed:
// Provides examples showing std::seed_seq is not a bijection
// i.e., that some seeds get repeated for different inputs
// and thus some other seeds must never be generated
#include <random>
#include <iostream>
#include <iomanip>
#include <cstddef>
@imneme
imneme / randutils.hpp
Last active September 25, 2024 13:41
Addresses common issues with C++11 random number generation; makes good seeding easier, and makes using RNGs easy while retaining all the power.
/*
* Random-Number Utilities (randutil)
* Addresses common issues with C++11 random number generation.
* Makes good seeding easier, and makes using RNGs easy while retaining
* all the power.
*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 Melissa E. O'Neill
*
@imneme
imneme / xorshift.hpp
Last active February 15, 2023 17:47
A Family of Truncated XorShift* PRNGs
#ifndef XORSHIFT_HPP_INCLUDED
#define XORSHIFT_HPP_INCLUDED 1
/*
* A C++ implementation of a family of truncated XorShift* generators.
*
* The MIT License (MIT)
*
* Copyright (c) 2017-19 Melissa E. O'Neill
*
@imneme
imneme / xoroshiro.hpp
Last active December 3, 2020 22:37
A C++ implementation of a family of Xoroshiro+ generators
#ifndef XOROSHIRO_HPP_INCLUDED
#define XOROSHIRO_HPP_INCLUDED 1
/*
* A C++ implementation of a family of Xoroshiro generators.
*
* See:
* https://en.wikipedia.org/wiki/Xoroshiro128%2B
* http://xoroshiro.di.unimi.it/xoroshiro128plus.c
*
@imneme
imneme / jsf.hpp
Created May 28, 2018 02:40
A C++ Implementation of Bob Jenkins's Small Fast Noncryptographic PRNG (JSF)
#ifndef JSF_HPP_INCLUDED
#define JSF_HPP_INCLUDED 1
/*
* A C++ implementation of a Bob Jenkins Small Fast (Noncryptographic) PRNGs
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Melissa E. O'Neill
*
@imneme
imneme / gjrand.hpp
Created May 28, 2018 07:45
A C++ implementation of David Blackman's GJrand PRNG(s)
#ifndef GJRAND_HPP_INCLUDED
#define GJRAND_HPP_INCLUDED 1
/*
* A C++ implementation of David Blackman's GJrand PRNG(s)
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Melissa E. O'Neill
*
@imneme
imneme / sfc.hpp
Last active July 6, 2024 10:23
A C++ implementation of Chris Doty-Humphrey's SFC PRNG(s)
#ifndef SFC_HPP_INCLUDED
#define SFC_HPP_INCLUDED 1
/*
* A C++ implementation of Chris Doty-Humphrey's SFC PRNG(s)
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Melissa E. O'Neill
*
@imneme
imneme / lehmer.hpp
Created June 9, 2018 20:39
A C++ implementation of 128-bit Lehmer-style PRNGs
#ifndef LEHMER_HPP_INCLUDED
#define LEHMER_HPP_INCLUDED 1
/*
* A C++ implementation of fast, 128-bit, Lehmer-style PRNGs
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Melissa E. O'Neill
*
@imneme
imneme / rng_adapters.hpp
Created June 9, 2018 20:43
A C++ implementation of a set of PRNG adapters
#ifndef RND_ADAPTERS_HPP_INCLUDED
#define RND_ADAPTERS_HPP_INCLUDED 1
/*
* A C++ implementation of a set of PRNG adapters.
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Melissa E. O'Neill
*
@imneme
imneme / xoshiro-bad-repeats.c
Created June 11, 2018 03:55
Xoshiro256** Bad Repeats Demonstration
/*
* Xoshiro256** Bad Repeats Demonstration
*
* gcc -std=c99 -Wall -o xoshiro-bad-repeats xoshiro-bad-repeats.c
* ./xoshiro-bad-repeats | less
*
* In a PRNG the size of Xoshiro256**, we should expect about 10 "5-in-7"
* repeats. Xoshiro256** has more than 18 billion billion of them, which
* is rather too many. In fact, the number of bad repeats is larger than
* the 2**64 range of the generator!