-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4.1.11.1 Random shuffle operation
60 lines (52 loc) · 1.35 KB
/
4.1.11.1 Random shuffle operation
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
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int rng_function(int range)
{
return std::rand() % range;
}
void print(const string & value)
{
cout << value << " ";
}
int main()
{
const unsigned RANDOM_SEED = 5;
std::srand(RANDOM_SEED);
vector<int> myvector;
vector<string> cards;
vector<string> card_names = { "A", "2", "3", "4" , "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
for (auto name : card_names)
{
//you can encode Spade, Heart, Diamond, Club as Unicode characters U+2660–2667
cards.push_back(name + "S");
cards.push_back(name + "H");
cards.push_back(name + "D");
cards.push_back(name + "C");
}
int n = 0;
vector<vector<string>> players(4);
n = cards.size();
random_shuffle(cards.begin(), cards.end(),rng_function);
for (auto i = cards.begin(); i != cards.begin() + (n/4); i++) {
players.at(0).push_back(*i);
}
for (auto i = cards.begin()+(n/4); i != cards.begin() + (n/2); i++) {
players.at(1).push_back(*i);
}
for (auto i = cards.begin()+(n/2); i != cards.begin() +(n-n/4); i++) {
players.at(2).push_back(*i);
}
for (auto i = cards.begin()+(n-n/4); i != cards.end(); i++) {
players.at(3).push_back(*i);
}
for (int i = 0; i < 4; i++) {
for_each(players.at(i).begin(), players.at(i).end(), print);
cout << endl;
cout << endl;
}
system("pause");
return 0;
}