libcruft-util/rand/xoshiro.hpp

54 lines
1.3 KiB
C++
Raw Normal View History

2020-08-17 14:30:55 +10:00
/*
* Written in 2019 by David Blackman and Sebastiano Vigna (vigna@acm.org)
*
* To the extent possible under law, the author has dedicated all copyright
* and related and neighboring rights to this software to the public domain
* worldwide. This software is distributed without any warranty.
*/
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright 2020, Danny Robson <danny@nerdcruft.net>
*/
#pragma once
#include "../std.hpp"
#include <array>
2020-08-17 14:30:55 +10:00
#include <limits>
#include <random>
2020-08-17 14:30:55 +10:00
///////////////////////////////////////////////////////////////////////////////
namespace cruft::rand {
class xoshiro256plusplus {
public:
using result_type = u64;
xoshiro256plusplus (u64 seed);
xoshiro256plusplus (std::seed_seq&);
2020-08-17 14:30:55 +10:00
static constexpr result_type min (void)
{
return std::numeric_limits<result_type>::min ();
}
static constexpr result_type max (void)
{
return std::numeric_limits<result_type>::max ();
}
result_type operator() (void);
void jump (void);
void long_jump (void);
private:
std::array<u64, 4> m_state;
2020-08-17 14:30:55 +10:00
};
}