Advertisement
axyd

High Precision Randomizer C++11

Oct 18th, 2017
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. /* 
  2.     High precision randomizer using time since 1970 as unique seed
  3.     Standard: C++11
  4. */
  5.  
  6. #include <iostream>
  7. #include <random> //mt19937 randomizer
  8. #include <chrono> //high resolution clock
  9. #include <functional> //bind
  10. using namespace std;
  11.  
  12. int main() {
  13.    
  14.     //accurate seed, seconds since 1970
  15.     auto seed= chrono::high_resolution_clock::now().time_since_epoch().count();
  16.  
  17.     //high accuracy randomizer with integer range
  18.     auto roll= std::bind(std::uniform_int_distribution<int>(1,4), mt19937(seed));
  19.  
  20.     int ctr= 100;
  21.     while(ctr) {
  22.         if(ctr%20 == 0) cout<<endl; //line break               
  23.         cout << roll() << ' ';
  24.         --ctr;
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement