Last active
September 22, 2018 22:34
-
-
Save pochemuto/b35851cd67339bef16a361eb1b66cd76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <unordered_map> | |
#include <vector> | |
#include <fstream> | |
#include <math.h> | |
#include <cctype> | |
#include <iostream> | |
#include <algorithm> | |
#include <random> | |
inline static const int SEED = 40623046; | |
using Permutation = std::unordered_map<char, char>; | |
inline Permutation CreateRandomPermutation(const std::vector<char> &alphabet, | |
std::mt19937 *generator) { | |
std::vector<char> target = alphabet; | |
// std::mt19937 gen(SEED); // так компилируется | |
// std::shuffle(target.begin(), target.end(), gen); | |
std::shuffle(target.begin(), target.end(), *generator); // так нет | |
Permutation permutation; | |
for (size_t i = 0; i < alphabet.size(); ++i) { | |
permutation[alphabet[i]] = target[i]; | |
} | |
return permutation; | |
} | |
inline void Test() { | |
std::mt19937 generator(SEED); | |
std::vector<char> alphabet{'a', 'b', 'c'}; | |
auto permutation = CreateRandomPermutation(alphabet, &generator); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment