ATLAS Offline Software
Control
CxxUtils
CxxUtils
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
28
class
FastReseededPRNG
{
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
44
result_type
operator()
();
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
FastReseededPRNG::min
static constexpr result_type min()
Definition:
FastReseededPRNG.h:39
max
constexpr double max()
Definition:
ap_fixedTest.cxx:33
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:91
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
Generated on Mon Dec 23 2024 21:10:28 for ATLAS Offline Software by
1.8.18