ATLAS Offline Software
Loading...
Searching...
No Matches
FastReseededPRNG.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2023 CERN for the benefit of the ATLAS collaboration
3
4----------------------------------------------------------------------
5Based on Xoroshiro code with copyright notice:
6Written in 2018 by David Blackman and Sebastiano Vigna (vigna@acm.org)
7
8To the extent possible under law, the author has dedicated all copyright
9and related and neighboring rights to this software to the public domain
10worldwide. This software is distributed without any warranty.
11
12See <http://creativecommons.org/publicdomain/zero/1.0/>.
13----------------------------------------------------------------------
14
15This provides a uniform random bit generator using xoroshiro128**
16seeded using 128 bit XXH3 to hash the provided seeds.
17
18Compared to other URBGs this is very cheap to construct, which is useful
19when the PRNG is reseeded every event and only used to generate a few random
20numbers.
21*/
22#ifndef PILEUPMT_FASTRESEEDEDPRNG_H
23#define PILEUPMT_FASTRESEEDEDPRNG_H
24#include <array>
25#include <cstdint>
26#include <limits>
27
29 public:
30 using result_type = std::uint64_t;
31 template <typename... Int>
32 FastReseededPRNG(Int... seed) {
33 const std::array<std::uint64_t, sizeof...(seed)> seed_array{
34 static_cast<std::uint64_t>(seed)...};
35 set_seed(seed_array.data(), seed_array.size());
36 }
37 FastReseededPRNG() = delete; // No default constructor. Always need a seed.
38
39 static constexpr result_type min() { return 0; }
40 static constexpr result_type max() {
41 return std::numeric_limits<std::uint64_t>::max();
42 }
43
45
46 private:
47 std::array<std::uint64_t, 2> m_seed_arr;
48 void set_seed(const std::uint64_t* start, std::size_t len);
49 std::uint64_t next();
50};
51
52#endif // PILEUPMT_FASTRESEEDEDPRNG_H
static constexpr result_type max()
void set_seed(const std::uint64_t *start, std::size_t len)
std::uint64_t next()
static constexpr result_type min()
result_type operator()()
FastReseededPRNG(Int... seed)
std::array< std::uint64_t, 2 > m_seed_arr
std::uint64_t result_type
FastReseededPRNG()=delete