-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerson.cpp
More file actions
46 lines (36 loc) · 1.38 KB
/
Copy pathPerson.cpp
File metadata and controls
46 lines (36 loc) · 1.38 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
#include "Person.h"
Person extractPerson(const string& firstName, const string& lastName) {
Person p = {firstName, lastName};
return p;
}
vector<Person> generateRandomPeople(const vector<Person>& people) {
vector<int> fnIndices(people.size());
vector<int> lnIndices(people.size());
iota(fnIndices.begin(), fnIndices.end(), 0);
iota(lnIndices.begin(), lnIndices.end(), 0);
mt19937 rng(random_device{}() ^ (uint64_t)chrono::steady_clock::now().time_since_epoch().count());
shuffle(fnIndices.begin(), fnIndices.end(), rng);
shuffle(lnIndices.begin(), lnIndices.end(), rng);
vector<Person> randomPeople;
for (int i = 0; i < people.size(); i++) {
randomPeople.push_back(extractPerson(people[fnIndices[i]].firstName, people[lnIndices[i]].lastName));
}
return randomPeople;
}
Person getRandomPerson(vector<Person> people) {
mt19937 rng(random_device{}() ^ (uint64_t)chrono::steady_clock::now().time_since_epoch().count());
shuffle(people.begin(), people.end(), rng);
return people[0];
}
void printPeople(const vector<Person>& people) {
for (int i = 0; i < people.size(); i++) {
cout << "[" << i+1 << "]: " << people[i] << endl;
}
}
ostream& printPerson(const Person& person) {
return cout << person << endl;
}
ostream& operator<<(ostream& os, const Person& p) {
os << p.firstName << " " << p.lastName;
return os;
}