Skip to content

A simple `UniformRandomBitGenerator` wrapper for the xoshiro256*** and xoroshiro128+ PRNGs

License

Notifications You must be signed in to change notification settings

morinim/xoshiro256ss

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple UniformRandomBitGenerator wrapper for the xoshiro256** and xoroshiro128+ PRNGs (see https://prng.di.unimi.it/).

Features

Usage

#include <iomanip>
#include <map>

#include "xoshiro256ss.h"

void test_xoshiro256ss()
{
  vigna::xoshiro256ss gen;

  std::random_device dev;
  gen.seed(dev());

  std::uniform_int_distribution<> dist(0, 10);

  std::map<unsigned, unsigned> hist;

  for(unsigned n(0); n < 1000000; ++n)
    ++hist[dist(gen)];

  std::cout << "XOSHIRO256**\n";
  for(auto p : hist)
    std::cout << std::setw(3) << p.first << ' '
              << std::string(p.second / 10000, '*') << '\n';
}

void test_xoroshiro128p()
{
  vigna::xoroshiro128p gen;

  std::random_device dev;
  gen.seed(dev());

  std::uniform_int_distribution<> dist(0, 10);

  std::map<unsigned, unsigned> hist;

  for(unsigned n(0); n < 1000000; ++n)
    ++hist[dist(gen)];

  std::cout << "XOROSHIRO128+\n";
  for(auto p : hist)
    std::cout << std::setw(3) << p.first << ' '
              << std::string(p.second / 10000, '*') << '\n';
}

int main()
{
  test_xoshiro256ss();
  test_xoroshiro128p();
}

and the output is something like:

XOSHIRO256**
  0 *********
  1 *********
  2 *********
  3 *********
  4 *********
  5 *********
  6 *********
  7 *********
  8 *********
  9 *********
 10 *********
XOROSHIRO128+
  0 *********
  1 *********
  2 *********
  3 *********
  4 *********
  5 *********
  6 *********
  7 *********
  8 *********
  9 *********
 10 *********

(source code)

Remarks

  • The implementation is only partially a C++11 RandomNumberEngine missing a constructor that creates an engine whose initial state is determined by a single call to SeedSequence::generate.

  • There are many xoshiro / xoroshiro generators. Since we wanted to keep code clean and maintenable, only xoshiro256** and xoroshiro128+ are implemented.

    They're all-purpose (not cryptographically secure) generators with excellent speed, a large state space and cover almost all general use cases.

    By default use xoshiro256**. If you're tight on space use xoroshiro128+.

About

A simple `UniformRandomBitGenerator` wrapper for the xoshiro256*** and xoroshiro128+ PRNGs

Topics

Resources

License

Stars

Watchers

Forks

Languages