Use of qsrand, random method that is not random

后端 未结 7 2650
误落风尘
误落风尘 2021-02-19 00:12

I\'m having a strange problem here, and I can\'t manage to find a good explanation to it, so I thought of asking you guys :

Consider the following method :



        
7条回答
  •  别那么骄傲
    2021-02-19 00:40

    modern Qt c++ 11

    #include 
    #include "QDateTime"
    
    int getRand(int min, int max){
        unsigned int ms = static_cast(QDateTime::currentMSecsSinceEpoch());
        std::mt19937 gen(ms);
        std::uniform_int_distribution<> uid(min, max);    
        return uid(gen);
    }
    

提交回复
热议问题