Last active
June 24, 2023 20:41
-
-
Save adk7712/cbfcd80743683199faae20f0097fe382 to your computer and use it in GitHub Desktop.
A simple C++ code snippet to generate a random number
This file contains hidden or 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 <iostream> | |
#include <random> | |
int main() { | |
std::random_device rd; | |
std::mt19937 gen(rd()); | |
int upper = 10; | |
int lower = 1; | |
// Generate random number between 1 and 10. | |
// Inclusive of upper and lower limits | |
std::uniform_int_distribution<> distr(lower, upper); | |
int randomNumber = distr(gen); | |
std::cout << "Random Number: " << randomNumber << std::endl; // Print random number | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment