-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathraidutils.hpp
More file actions
76 lines (63 loc) · 1.55 KB
/
raidutils.hpp
File metadata and controls
76 lines (63 loc) · 1.55 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
72
73
74
75
76
#ifndef RAID_UTILS_H
#define RAID_UTILS_H
#include <iostream>
#include <vector>
#include <random>
#include <string>
#define LINE "\n"
#define SPACE " "
using namespace std;
int randomint(int min, int max) {
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dist(min, max);
return dist(mt);
}
double randomdouble(double min, double max) {
random_device rd;
mt19937 mt(rd());
uniform_real_distribution<double> dist(min, max);
return dist(mt);
}
bool randbool() {
return randomint(0, 1) ? true : false;
}
template<typename T, size_t N>
T randarray(const T (&arr)[N]) {
return arr[randomint(0, N - 1)];
}
template<typename T>
T randvector(const vector<T>& vec) {
return vec[randomint(0, vec.size() - 1)];
}
template<typename T>
string to_string(const T& value) {
return std::to_string(value);
}
string to_string(const string& value) {
return value;
}
string to_string(const char* value) {
return value;
}
template<typename T>
string concatenate_strings(const T& first) {
return to_string(first);
}
template<typename T, typename... Args>
string concatenate_strings(const T& first, const Args&... args) {
return to_string(first) + concatenate_strings(args...);
}
template<typename... Args>
void print(const Args&... args) {
cout << concatenate_strings(args...) << LINE;
}
template<typename T>
void println(T msg, int newlines = 0) {
string newlinechar = "";
for (int i = 0; i < newlines + 1; ++i) {
newlinechar += LINE;
}
cout << msg << newlinechar;
}
#endif // RAID_UTILS_H