-
Notifications
You must be signed in to change notification settings - Fork 10
/
Day-090.cpp
28 lines (26 loc) · 883 Bytes
/
Day-090.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
#include <bits/stdc++.h>
using namespace std;
class Solution{
vector<int>included;
public:
int generateRandomNumber(const array<int, 5>&excluded, const int &n) {
set<int>exclude(excluded.begin(), excluded.end());
for(int i = 0;i<n;++i){
if(exclude.find(i)==exclude.end()){
included.push_back(i);
}
}
int inclusion_size = static_cast<int>(included.size());
// random number generation
std::random_device rnd;
std::mt19937 rng(rnd());
std::uniform_int_distribution<int> distribution(0,inclusion_size);
return included[distribution(rng)];
}
};
int main(void){
array<int , 5> exclude{2, 8, 11, 19, 23};
Solution s1;
cout << s1.generateRandomNumber(exclude, 30) << '\n';
return 0;
}