GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Reputeless/Xoshiro-cpp: Header-only Xoshiro/Xoroshiro PRNG wrapper library for modern C++ (C++17/C++20)

BranchesTags
Open more actions menu

Latest commit

 

History

13 Commits
13 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
XoshiroCpp.hpp
XoshiroCpp.hpp
 
 
example.cpp
example.cpp
 
 
xoshiro-cpp.png
xoshiro-cpp.png
 
 

Repository files navigation

Xoshiro-cpp

Xoshiro-cpp is a header-only pseudorandom number generator library for modern C++.
Based on David Blackman and Sebastiano Vigna's xoshiro/xoroshiro generators.

Features

  • Meets the std::uniform_random_bit_generator concept (C++20)
    • Works with std::uniform_int_distribution, std::shuffle and the other standard library functions
  • Mostly constexpr in C++17
  • Serialize / deserialize
  • Utility function double DoubleFromBits(uint64 v);
    • Converts given uint64 value v into a 64-bit floating point value in the range of [0.0, 1.0)
PRNG Output bits Period Footprint
SplitMix64 64 bits 2^64 8 bytes
xoshiro256+ 64 bits 2^256-1 32 bytes
xoshiro256++ 64 bits 2^256-1 32 bytes
xoshiro256** 64 bits 2^256-1 32 bytes
xoroshiro128+ 64 bits 2^128-1 16 bytes
xoroshiro128++ 64 bits 2^128-1 16 bytes
xoroshiro128** 64 bits 2^128-1 16 bytes
xoshiro128+ 32 bits 2^128-1 16 bytes
xoshiro128++ 32 bits 2^128-1 16 bytes
xoshiro128** 32 bits 2^128-1 16 bytes

Examples

# include <iostream>
# include "XoshiroCpp.hpp"

int main()
{
    using namespace XoshiroCpp;

    const std::uint64_t seed = 12345;

    Xoshiro256PlusPlus rng(seed);

    for (int i = 0; i < 5; ++i)
    {
        std::cout << rng() << '\n';
    }
}
10201931350592234856
3780764549115216544
1570246627180645737
3237956550421933520
4899705286669081817

# include <iostream>
# include <random>
# include "XoshiroCpp.hpp"

int main()
{
    using namespace XoshiroCpp;

    const std::uint64_t seed = 12345;

    Xoshiro256PlusPlus rng(seed);

    std::uniform_int_distribution<int> dist(1, 6);

    for (int i = 0; i < 5; ++i)
    {
        std::cout << dist(rng) << '\n';
    }
}
1
5
4
3
6

# include <algorithm>
# include <iostream>
# include "XoshiroCpp.hpp"

int main()
{
    using namespace XoshiroCpp;

    const std::uint64_t seed = 12345;

    Xoshiro256PlusPlus rng(seed);

    std::array<int, 10> ar = { 0,1,2,3,4,5,6,7,8,9 };

    std::shuffle(ar.begin(), ar.end(), rng);

    for (const auto& x : ar)
    {
        std::cout << x << '\n';
    }
}
6
3
7
2
8
5
4
9
1
0

# include <iostream>
# include "XoshiroCpp.hpp"

int main()
{
    using namespace XoshiroCpp;

    const std::uint64_t seed = 12345;

    Xoshiro256PlusPlus rng(seed);

    for (int i = 0; i < 5; ++i)
    {
        std::cout << DoubleFromBits(rng()) << '\n';
    }
}
0.553048
0.204956
0.0851232
0.17553
0.265614

# include <iostream>
# include "XoshiroCpp.hpp"

int main()
{
    using namespace XoshiroCpp;

    // This example seed sequence { 111, 222, 333, 444 } is poorly
    // distributed (has a lot of '0' bits) and it is not suitable
    // for directly use in the generator's internal state.
    // SplitMix64 PRNG can be used to increase entropy.
    const Xoshiro256Plus::state_type initialStateA =
    {
        SplitMix64{ 111 }(),
        SplitMix64{ 222 }(),
        SplitMix64{ 333 }(),
        SplitMix64{ 444 }(),
    };

    Xoshiro256PlusPlus rngA(initialStateA);

    for (int i = 0; i < 3; ++i)
    {
        std::cout << rngA() << '\n';
    }

    const Xoshiro256Plus::state_type state = rngA.serialize();

    Xoshiro256PlusPlus rngB(state);

    for (int i = 0; i < 3; ++i)
    {
        std::cout << std::boolalpha << (rngA() == rngB()) << '\n';
    }

    rngB.deserialize(initialStateA);

    for (int i = 0; i < 3; ++i)
    {
        std::cout << rngB() << '\n';
    }
}
9228892280983206813
11892737616047535485
12786908792686548306
true
true
true
9228892280983206813
11892737616047535485
12786908792686548306

Roadmap

  • SplitMix64
  • xoshiro256+
  • xoshiro256++
  • xoshiro256**
  • xoroshiro128+
  • xoroshiro128++
  • xoroshiro128**
  • xoshiro128+
  • xoshiro128++
  • xoshiro128**
  • xoroshiro64*
  • xoroshiro64**

License

Xoshiro-cpp is distributed under the MIT license.

About

Header-only Xoshiro/Xoroshiro PRNG wrapper library for modern C++ (C++17/C++20)

Topics

cppcpp17cpp20prngrngxoshiroxoshiro256

Resources

Readme
MIT license
Activity

Stars

208 stars

Watchers

12 watching

Forks

21 forks
Report repository

Releases

Sponsor this project

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.