0

I have simple random generator code that returns different numbers using cl and g++ compilers in Windows. Strangely, the same code in Qt doesn't return different numbers. The code is

#include <random>
#include <iostream>

class RandGen
{
public:
    RandGen() :  m_generator(m_seeder())
    {
    }

    std::random_device m_seeder;
    std::mt19937 m_generator;

    int getNum()
    {
        std::uniform_int_distribution<> dist(0,5);
        return dist(m_generator);
    }
};


int main()
{
    RandGen rg;

    for(int i(0); i < 5; ++i){
        std::cout << rg.getNum() << " ";
    }
    std::cout << std::endl;

    return 0;
}

In Visual Studio, the result is

enter image description here

With g++ via cygwin, the result is

enter image description here

Now running same code with Qt using Desktop Qt 5.9.1 MinGW 32bit, it returns same values.

enter image description here

The .pro file is

QT += core
QT -= gui
CONFIG += c++11
TARGET = Ports
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
CroCo
  • 5,531
  • 9
  • 56
  • 88
  • @SteakOverflow, but it works with g++. I assume g++ in cygwin and mingw is same, right?! – CroCo Jan 24 '18 at 08:44
  • No. First the cygwin version is probably newer. Second both have gcc ports for windows, but they are not identical. Qts gcc is taken from msys, i believe (not sure). Note that there also is msys2. – SteakOverflow Jan 24 '18 at 08:48
  • Anyway the answers from that thread still apply. – SteakOverflow Jan 24 '18 at 08:51
  • @SteakOverflow, running `mingw32-g++ -std=c++11 main1.cpp -o test3` with `(GCC) 5.3.0` yields same problem. – CroCo Jan 24 '18 at 08:56

0 Answers0