I don't understand why I keep getting the same 1st digit when I've already seeded a default_random_engine with time(0)(C++ Primer tell me to usetime(0)). Is it a problem of my computer? (Ubuntu, C++11)
I tried on a online compiler and it's interesting that I got the same 1st digit using gcc while not using clang++.
https://wandbox.org/permlink/kiUg1BW1RkDL8y8c
Code:
#include <iostream>
#include <ctime>
#include <random>
using namespace std;
int main(){
auto t = time(0);
cout << "time: " << t << endl;
default_random_engine e(t);
uniform_int_distribution<int> uniform_dist(0, 9);
cout << "sequence:";
for(int i = 0; i < 10; i++){
cout << uniform_dist(e);
}
cout << endl;
return 0;
}
Result:
As you can see I keep getting 6 as the first digit of a random number, no matter I use clang++ or g++ to compile.
