@@ -37,8 +37,8 @@ const std::string DIGITS_SET = "0123456789";
37
37
38
38
// Used to determine the set of allowed characters
39
39
// for the String method of the Rand class
40
- const int LOWER = 1;
41
- const int UPPER = 1 << 1;
40
+ const int LOWER = 1;
41
+ const int UPPER = 1 << 1;
42
42
const int DIGITS = 1 << 2;
43
43
44
44
// Returns a random value of the following types
@@ -48,9 +48,9 @@ const int DIGITS = 1 << 2;
48
48
// Rand rand(argc, argv);
49
49
// int randomInt = rand.Int();
50
50
// string randomString = rand.String(10, DIGITS);
51
- //
51
+ //
52
52
// @author NouemanKHAL
53
- //
53
+ //
54
54
class Rand {
55
55
unsigned int seed;
56
56
@@ -61,7 +61,7 @@ class Rand {
61
61
return 0;
62
62
}
63
63
64
- public:
64
+ public:
65
65
Rand(unsigned int _seed = 0) : seed(_seed) { srand(seed); }
66
66
67
67
Rand(int argc, char* argv[]) {
@@ -70,28 +70,28 @@ public:
70
70
}
71
71
72
72
// Returns an random int value in the range [from, to] inclusive
73
- int Int(int from, int to) {
74
- assert(from <= to);
75
- return rand() % (to - from) + from;
76
- }
73
+ int Int(int from, int to) {
74
+ assert(from <= to);
75
+ return rand() % (to - from) + from;
76
+ }
77
77
78
78
// Returns an random long long value in the range [from, to] inclusive
79
79
long long Long(long long from, long long to) {
80
- assert(from <= to);
80
+ assert(from <= to);
81
81
return rand() % (to - from) + from;
82
82
}
83
83
84
84
// Returns an random double value in the range [from, to] inclusive
85
85
double Double(double from, double to) {
86
- assert(from <= to);
86
+ assert(from <= to);
87
87
double tmp = (double)rand() / RAND_MAX;
88
88
return from + tmp * (to - from);
89
89
}
90
90
91
91
// Returns an random char value in the range [from, to] inclusive
92
92
// Parameters are optional
93
93
char Char(char from = CHAR_MIN, char to = CHAR_MAX) {
94
- assert(from <= to);
94
+ assert(from <= to);
95
95
return static_cast<char>(Int(from, to));
96
96
}
97
97
@@ -119,21 +119,19 @@ public:
119
119
// Returns an random digit character
120
120
// Parameters are optional, by default returns a random digit character in the
121
121
// range ['0', '9'] inclusive
122
- char Digit(char from = '0', char to = '9') {
123
- assert(from <= to);
124
- return Char(from, to);
125
- }
122
+ char Digit(char from = '0', char to = '9') {
123
+ assert(from <= to);
124
+ return Char(from, to);
125
+ }
126
126
127
127
// Returns a random alphanumerical character
128
128
char AlphaNum() {
129
129
if (rand() & 1) return Alpha();
130
130
return Digit();
131
131
}
132
-
133
- // Returns a random boolean value.
134
- bool Bool() {
135
- return bool(rand() & 1);
136
- }
132
+
133
+ // Returns a random boolean value.
134
+ bool Bool() { return bool(rand() & 1); }
137
135
138
136
// Returns an std::string of length size consisting only of characters allowed
139
137
// in the given mask using the constants LOWER, UPPER, DIGITS Example: Rand
0 commit comments