Last active
August 29, 2015 14:12
-
-
Save cjxgm/99efff412ca225242b13 to your computer and use it in GitHub Desktop.
generate 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
// modified from the example in http://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution | |
#include <random> | |
#include <iostream> | |
int main() | |
{ | |
std::random_device rd; // this is very likely a "real" random number generator | |
std::mt19937 gen(rd()); // pseudo random number GENerator with seed from "rd" | |
std::uniform_int_distribution<> dis(0, 100); // DIStribute the result uniformly inside closed interval [0, 100] | |
int array[10]; | |
for (auto& x: array) x = dis(gen); | |
for (auto x: array) std::cout << x << ' '; | |
std::cout << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment