Notes:
- My compiler is g++ 5.1.0-2 with c++14 language standards
- My IDE is Code::Blocks (I tried the code on Dev-C++ too)
- The online IDEs I tested the code on were http://cpp.sh/ (C++ shell) and https://www.codechef.com/ide (CodeChef.com's IDE) both running c++14
- The code runs ok when using an online IDE, which puzzles me even more.
Here is the code:
#include <iostream>
#include <random>
#include <cstdlib>
#include <ctime>
#include <chrono>
int main() {
srand(time(0));
long long seed = rand();
std::default_random_engine rand_num(seed);
std::uniform_int_distribution<long long> range(0, 10);
long long a = range(rand_num);
long long b = rand_num();
std::cout<<seed<<"\n"; // the seed is different every time (tested)
std::cout<<a<<"\n";
std::cout<<b<<"\n";
system("pause");
return 0;
}
The one with std::uniform_int_distribution (a) isn't random when running the code on my own computer but works ok and creates a random number on the online IDEs.
The one without std::uniform_int_distribution (b) works ok with both online IDEs and my own computer.
What's the problem? How can I fix it?
UPDATE: The code works ok with mt19937 engine (std::mt19937 and std::mt19937_64)