Skip to content

Instantly share code, notes, and snippets.

@imneme
imneme / xoroshiro.hpp
Last active Dec 3, 2020
A C++ implementation of a family of Xoroshiro+ generators
View xoroshiro.hpp
#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 / arc4.hpp
Created Jul 5, 2018
A C++ port of the OpenBSD Arc4 random number generator
View arc4.hpp
#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 / rng_adapters.hpp
Created Jun 9, 2018
A C++ implementation of a set of PRNG adapters
View rng_adapters.hpp
#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 / seeding_bias.cpp
Last active Jun 24, 2019
Seeding Bias Test
View seeding_bias.cpp
/*
* 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 / xoshiro-bad-repeats.c
Created Jun 11, 2018
Xoshiro256** Bad Repeats Demonstration
View xoshiro-bad-repeats.c
/*
* 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!
View badseed.cpp
// 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>