Skip to content

Instantly share code, notes, and snippets.

@JMassey1
Created November 16, 2021 17:28
Show Gist options
  • Save JMassey1/8d2f89cefde4f53989cee52b086a9e5a to your computer and use it in GitHub Desktop.
Save JMassey1/8d2f89cefde4f53989cee52b086a9e5a to your computer and use it in GitHub Desktop.
Mersenne random engine (C++)
void generateRandomVector(std::vector<int>& inputVector, const std::pair<int,int> RAND_BOUNDS, const int VEC_SIZE) {
std::random_device rnd_device;
std::mt19937 mersenne_engine{rnd_device()};
std::uniform_int_distribution<int> distribution {RAND_BOUNDS.first, RAND_BOUNDS.second};
auto generator = [&distribution, &mersenne_engine]() {
return distribution(mersenne_engine);
};
inputVector.clear();
inputVector.resize(VEC_SIZE);
std::generate(inputVector.begin(), inputVector.end(), generator);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment