-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRNG.hxx
76 lines (45 loc) · 1.94 KB
/
RNG.hxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright Kabuki Starship� <kabukistarship.com>.
#include "RNG.h"
//
#include <random>
namespace _ {
// static std::random_device rd;
// static std::default_random_engine rng(rd);
static std::default_random_engine rng;
IUC RandomUI4() { return rng(); }
IUC RandomSeed() { return std::random_device()(); }
void RandomizeSeed() { return rng.seed(RandomSeed()); }
BOL RandomBOL() { return (BOL)RandomUI4(); }
IUA RandomUIA() { return (IUA)RandomUI4(); }
ISA RandomSIA() { return (ISA)RandomUIA(); }
IUB RandomUI2() { return (IUB)RandomUI4(); }
ISB RandomSIB() { return (ISB)RandomUI2(); }
ISC Randomint() { return (ISC)RandomUI4(); }
IUD RandomUI8() {
IUD a = RandomUI4(), b = RandomUI4();
return (ISD)(a | (b << 32));
}
ISD RandomSID() { return (ISD)RandomUI8(); }
void RandomNumber(BOL& result) { result = BOL(RandomUI4() & 1); }
void RandomNumber(IUA& result) { result = RandomUIA(); }
void RandomNumber(ISA& result) { result = RandomSIA(); }
void RandomNumber(IUB& result) { result = RandomUI2(); }
void RandomNumber(ISB& result) { result = RandomSIB(); }
void RandomNumber(IUC& result) { result = RandomUI4(); }
void RandomNumber(ISC& result) { result = Randomint(); }
void RandomNumber(IUD& result) { result = RandomUI8(); }
void RandomNumber(ISD& result) { result = RandomSID(); }
template<typename IS>
IS TRandom(IS min, IS max) {
std::uniform_int_distribution<IS> dist(min, max);
return dist(rng);
}
IUA Random(IUA min, IUA max) { return IUA(TRandom<IUB>(min, max)); }
ISA Random(ISA min, ISA max) { return ISA(TRandom<ISB>(min, max)); }
IUB Random(IUB min, IUB max) { return TRandom<IUB>(min, max); }
ISB Random(ISB min, ISB max) { return TRandom<ISB>(min, max); }
IUC Random(IUC min, IUC max) { return TRandom<IUC>(min, max); }
ISC Random(ISC min, ISC max) { return TRandom<ISC>(min, max); }
IUD Random(IUD min, IUD max) { return TRandom<IUD>(min, max); }
ISD Random(ISD min, ISD max) { return TRandom<ISD>(min, max); }
} //< namespace _