-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.cpp
34 lines (26 loc) · 835 Bytes
/
code.cpp
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
/* code.cpp
* Copyright © 2015, Brian Derr <[email protected]>
*/
#include "code.h"
Code::Code(int length) : Code(length, std::random_device{}()) {}
Code::Code(int length, unsigned int seed) :
dist_(std::uniform_int_distribution<>(1, 6)), engine_(std::default_random_engine(seed)),
length_(length) {}
Code::Code(std::vector<int> secret) : code_(secret), length_(secret.size()) {}
// void Code::initialize(unsigned int seed) {
// engine_ = std::default_random_engine (seed);
// dist_ = std::uniform_int_distribution<> (1, 6);
// initialized_ = true;
// }
int Code::GetRandomNumber() {
return dist_(engine_);
}
// Create a new code that is length_ long.
void Code::Create() {
if (code_.size() > 0) {
code_.clear();
}
for (int i = 0; i < length_; ++i) {
code_.push_back(GetRandomNumber());
}
}