ATLAS Offline Software
FastReseededPRNG.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2023 CERN for the benefit of the ATLAS collaboration
3 
4 ----------------------------------------------------------------------
5 Based on Xoroshiro code with copyright notice:
6 Written in 2018 by David Blackman and Sebastiano Vigna (vigna@acm.org)
7 
8 To the extent possible under law, the author has dedicated all copyright
9 and related and neighboring rights to this software to the public domain
10 worldwide. This software is distributed without any warranty.
11 
12 See <http://creativecommons.org/publicdomain/zero/1.0/>.
13 ----------------------------------------------------------------------
14 
15 This provides a uniform random bit generator using xoroshiro128**
16 seeded using 128 bit XXH3 to hash the provided seeds.
17 
18 Compared to other URBGs this is very cheap to construct, which is useful
19 when the PRNG is reseeded every event and only used to generate a few random
20 numbers.
21 */
22 #ifndef PILEUPMT_FASTRESEEDEDPRNG_H
23 #define PILEUPMT_FASTRESEEDEDPRNG_H
24 #include <array>
25 #include <cstdint>
26 #include <limits>
27 
29  public:
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() {
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);
50 };
51 
52 #endif // PILEUPMT_FASTRESEEDEDPRNG_H
FastReseededPRNG::min
static constexpr result_type min()
Definition: FastReseededPRNG.h:39
max
#define max(a, b)
Definition: cfImp.cxx:41
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
FastReseededPRNG::max
static constexpr result_type max()
Definition: FastReseededPRNG.h:40
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
lumiFormat.array
array
Definition: lumiFormat.py:98
FastReseededPRNG::next
std::uint64_t next()
Definition: FastReseededPRNG.cxx:46
FastReseededPRNG::set_seed
void set_seed(const std::uint64_t *start, std::size_t len)
Definition: FastReseededPRNG.cxx:33
FastReseededPRNG::operator()
result_type operator()()
Definition: FastReseededPRNG.cxx:28
FastReseededPRNG::result_type
std::uint64_t result_type
Definition: FastReseededPRNG.h:30
FastReseededPRNG::FastReseededPRNG
FastReseededPRNG(Int... seed)
Definition: FastReseededPRNG.h:32
FastReseededPRNG::m_seed_arr
std::array< std::uint64_t, 2 > m_seed_arr
Definition: FastReseededPRNG.h:47
FastReseededPRNG::FastReseededPRNG
FastReseededPRNG()=delete
FastReseededPRNG
Definition: FastReseededPRNG.h:28