axyd icon

High Precision Randomizer C++11

axyd | PRO | 10/18/17 11:13:56 PM UTC | 0 ⭐ | 751 👁️ | Never ⏰ | []
C++ |

630 B

|

None

|

0 👍

/

0 👎

/*  
    High precision randomizer using time since 1970 as unique seed
    Standard: C++11
*/
 
#include <iostream>
#include <random> //mt19937 randomizer
#include <chrono> //high resolution clock
#include <functional> //bind
using namespace std;
 
int main() {
    
    //accurate seed, seconds since 1970
    auto seed= chrono::high_resolution_clock::now().time_since_epoch().count();
 
    //high accuracy randomizer with integer range
    auto roll= std::bind(std::uniform_int_distribution<int>(1,4), mt19937(seed));
 
    int ctr= 100;
    while(ctr) {
        if(ctr%20 == 0) cout<<endl; //line break                
        cout << roll() << ' ';
        --ctr;
    }
}

Comments