Skip to content

Instantly share code, notes, and snippets.

@cjxgm
Last active August 29, 2015 14:12
Show Gist options
  • Save cjxgm/99efff412ca225242b13 to your computer and use it in GitHub Desktop.
Save cjxgm/99efff412ca225242b13 to your computer and use it in GitHub Desktop.
generate random number
// 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