http://en.cppreference.com/w/cpp/numeric/random/rand
#include <cstdlib> #include <iostream> #include <ctime> int main() { std::srand(std::time(0)); // use current time as seed for random generator int random_variable = std::rand(); std::cout << "Random value on [0 " << RAND_MAX << "]: " << random_variable << '\n'; }
#include <random>
std::random_device rd;
std::uniform_int_distribution<int> dist(0, 9);
for (int n = 0; n < 10; ++n) {
std::cout<<dist(rd)<<"\n";
http://en.cppreference.com/w/cpp/header/random
http://en.cppreference.com/w/cpp/numeric/random/random_device
http://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution
No comments:
Post a Comment