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 / 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!
@imneme
imneme / seeding_bias.cpp
Last active June 24, 2019 01:06
Seeding Bias Test
/*
* Seeding Bias Test
*
* - Runs through all possible seeds and examines the output for
* bias. Doing so is only practical for 32-bit (or less) seeds
* and 32-bit (or less) output.
*
* Compilation note:
*
* - You need to define the following preprocessor symbols to compile this
@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 / arc4.hpp
Created July 5, 2018 13:04
A C++ port of the OpenBSD Arc4 random number generator
#ifndef ARC4_HPP_INCLUDED
#define ARC4_HPP_INCLUDED 1
/*
* A C++ port of the OpenBSD Arc4 random number generator
*
* The MIT License (MIT)
*
* Copyright (C) 1996 David Mazieres <dm@lcs.mit.edu> for the OpenBSD project
* C++ Port Copyright (c) 2014-18 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 / xoshiro256-similarity.c
Created December 4, 2020 22:37
This code shows self-similarity issues with Vigna's xoshiro256**. The original version of this code was written by Tyge Løvset.
/*
* Show self-similarity issues with Vigna's xoshiro256**
*
* Originally posted in a NumPy developers discussion by Tyge Løvset
* but simplified to only mix 32 outputs.
*
* Compile, and then test with PractRand by running
*
* ./xoshiro256-similarity \
* | ./RNG_test stdin64 -te 1 -tlmin 15 -tlmax 50 -tlmaxonly -multithreaded
@imneme
imneme / xoshiro.hpp
Created July 4, 2018 04:23
A C++ implementation of a family of Xoshiro generators
#ifndef XOSHIRO_HPP_INCLUDED
#define XOSHIRO_HPP_INCLUDED 1
/*
* A C++ implementation of a family of Xoshiro generators.
*
* See:
* https://arxiv.org/abs/1805.01407
* http://xoshiro.di.unimi.it/xoshiro256plus.c
* http://xoshiro.di.unimi.it/xoshiro256starstar.c
@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 / 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
*