vendredi 8 janvier 2016

why is

Notes:

  1. My compiler is g++ 5.10-2 with c++14 language standards
  2. My IDE is Code::Blocks (I tried the code on Dev-C++ too)
  3. The online IDEs I tested the code on were http://cpp.sh/ (C++ shell) and http://ift.tt/1Zflry8 (CodeChef.com's IDE) both running c++14
  4. 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<<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?




Aucun commentaire:

Enregistrer un commentaire