Created
April 20, 2022 08:28
-
-
Save datiti/406d73284f91ceac93a828b650e06e4e to your computer and use it in GitHub Desktop.
C++ random generate int in range
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
// source: https://stackoverflow.com/questions/288739/generate-random-numbers-uniformly-over-an-entire-range | |
#include <iostream> | |
#include <random> | |
int main() { | |
const int range_from = 0; | |
const int range_to = 6; | |
std::random_device rand_dev; | |
std::mt19937 generator(rand_dev()); | |
std::uniform_int_distribution<int> distr(range_from, range_to); | |
cerr << distr(generator) << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment