Medial Code Documentation
Loading...
Searching...
No Matches
globalRNG.h
1#ifndef __GLOBAL_RNG_H__
2#define __GLOBAL_RNG_H__
3#pragma once
4
5#include <random>
6
8{
9 public:
10 static std::minstd_rand::result_type rand() {return getInstance()._rng();};
11 static unsigned int rand30() {return ((getInstance()._rng() << 15) ^ getInstance()._rng()) & 0x3fffffff;};
12 static void srand(std::minstd_rand::result_type val) {getInstance()._rng.seed(val);};
13 static const std::minstd_rand::result_type max() {return getInstance()._rng.max();};
14
15 private:
16 std::minstd_rand _rng;
17
18 static globalRNG& getInstance()
19 {
20 static globalRNG instance; // instansiated on first call
21 return instance;
22 }
23
24 globalRNG() : _rng(20150715) {}; // constructor
25
26 globalRNG(globalRNG const&) {fprintf(stderr, "Error: copying is forbidden for the globalRNG object\n"); exit(-1);}; // no copy constructor
27 void operator=(globalRNG const&) {fprintf(stderr, "Error: assignment is forbidden for the globalRNG object\n"); exit(-1);}; // no assignment operator
28
29};
30
31#endif
Definition globalRNG.h:8