OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
RNGStream.h
Go to the documentation of this file.
1//
2// Class RNGStream
3// This class takes care of RNG generator instances.
4//
5// Copyright (c) 2018, Christof Metzger-Kraus, Open Sourcerer
6// All rights reserved
7//
8// This file is part of OPAL.
9//
10// OPAL is free software: you can redistribute it and/or modify
11// it under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// You should have received a copy of the GNU General Public License
16// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17//
18#ifndef RNGSTREAM_H
19#define RNGSTREAM_H
20
21#include <random>
22
24{
25public:
26 static RNGStream* getInstance();
27 static RNGStream* getInstance(unsigned int seed);
28 static void deleteInstance(RNGStream* & generator);
29
30 static void setGlobalSeed(unsigned int seed);
31
32 static unsigned int getGlobalSeed();
33
34 std::mt19937_64 & getGenerator();
35
36 template <class DISTR>
37 typename DISTR::result_type getNext(DISTR & RNGDist) {
38 return RNGDist(RNGenerator_m);
39 }
40
41private:
44 isGlobal_m(true)
45 { }
46
47 RNGStream(unsigned int seed):
49 isGlobal_m(false)
50 { }
51
53 { }
54
56 static unsigned int globalSeed_sm;
57 static unsigned int numGlobalInstances_sm;
58 std::mt19937_64 RNGenerator_m;
60
61};
62#endif
int seed
The current random seed.
Definition: Options.cpp:37
static RNGStream * getInstance()
Definition: RNGStream.cpp:26
static void deleteInstance(RNGStream *&generator)
Definition: RNGStream.cpp:38
RNGStream(unsigned int seed)
Definition: RNGStream.h:47
static unsigned int getGlobalSeed()
Definition: RNGStream.cpp:60
bool isGlobal_m
Definition: RNGStream.h:59
DISTR::result_type getNext(DISTR &RNGDist)
Definition: RNGStream.h:37
static void setGlobalSeed(unsigned int seed)
Definition: RNGStream.cpp:53
static RNGStream * globalInstance_sm
Definition: RNGStream.h:55
RNGStream()
Definition: RNGStream.h:42
static unsigned int numGlobalInstances_sm
Definition: RNGStream.h:57
std::mt19937_64 RNGenerator_m
Definition: RNGStream.h:58
static unsigned int globalSeed_sm
Definition: RNGStream.h:56
std::mt19937_64 & getGenerator()
Definition: RNGStream.cpp:64
~RNGStream()
Definition: RNGStream.h:52