Created
November 16, 2021 17:28
-
-
Save JMassey1/8d2f89cefde4f53989cee52b086a9e5a to your computer and use it in GitHub Desktop.
Mersenne random engine (C++)
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
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