Using boost::random as the RNG for std::random_shuffle

前端 未结 4 1967
一向
一向 2020-12-29 12:51

I have a program that uses the mt19937 random number generator from boost::random. I need to do a random_shuffle and want the random numbers generated for this to be from th

4条回答
  •  执笔经年
    2020-12-29 13:16

    I thought it was worth pointing out that this is now pretty straightforward in C++11 using only the standard library:

    #include 
    #include 
    
    std::random_device rd;
    std::mt19937 randEng(rd());
    std::shuffle(vec.begin(), vec.end(), randEng);
    

提交回复
热议问题