-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRand.h
More file actions
71 lines (55 loc) · 1.33 KB
/
Rand.h
File metadata and controls
71 lines (55 loc) · 1.33 KB
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
/*
* Rand.h
*
* Created on: Apr 11, 2020
* Author: ans
*/
#ifndef RAND_H_
#define RAND_H_
#pragma once
#include <cstdlib> // std::rand
#include <limits> // std::numeric_limits
#include <random> // std::mt19937, std::random_device, std::uniform_int_distribution, std::uniform_real_distribution
#include <stdexcept> // std::runtime_error
#include <string> // std::string
constexpr unsigned char RAND_ALGO_NUM = 3;
class Rand {
public:
enum Algo {
RAND_ALGO_STD_RAND = 0,
RAND_ALGO_STD_MT19937 = 1,
RAND_ALGO_LEHMER32 = 2
};
Rand();
Rand(Algo algo);
virtual ~Rand();
void seed(unsigned int s);
void setAlgo(Algo n);
Algo getAlgo() const;
std::string str() const;
void setByteLimits(unsigned char from, unsigned char to);
void setIntLimits(int from, int to);
void setRealLimits(double from, double to);
unsigned char generateByte();
int generateInt();
double generateReal();
bool generateBool();
private:
Algo algo;
unsigned char byteMin;
unsigned char byteMax;
unsigned char byteHalf;
int intMin;
int intMax;
int intHalf;
double realMin;
double realMax;
double realHalf;
std::mt19937 mt;
std::uniform_int_distribution<unsigned char> byteDist;
std::uniform_int_distribution<int> intDist;
std::uniform_real_distribution<double> realDist;
uint32_t lehmer;
uint32_t lehmer32();
};
#endif /* RAND_H_ */