Skip to content

Instantly share code, notes, and snippets.

@pochemuto
Last active September 22, 2018 22:34
Show Gist options
  • Save pochemuto/b35851cd67339bef16a361eb1b66cd76 to your computer and use it in GitHub Desktop.
Save pochemuto/b35851cd67339bef16a361eb1b66cd76 to your computer and use it in GitHub Desktop.
#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