Advertisement
cd62131

random

Feb 27th, 2014
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <random>
  5. #include <chrono>
  6. using namespace std;
  7. int main() {
  8.   srand((unsigned) time(NULL));
  9.   int a = (int) (rand() / ((double) RAND_MAX + 1.) * 3.);
  10.  
  11.   unsigned seed = chrono::system_clock::now().time_since_epoch().count();
  12.   mt19937_64 generator(seed);
  13.   uniform_int_distribution<int> distribution(0, 2);
  14.   int b = distribution(generator);
  15.  
  16.   cout << "cstdlib: " << a << endl;
  17.   cout << "random (c++11): " << b << endl;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement