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

前端 未结 4 1971
一向
一向 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:26

    I'm using tr1 instead of boost::random here, but should not matter much.

    The following is a bit tricky, but it works.

    #include 
    #include 
    
    
    std::tr1::mt19937 engine;
    std::tr1::uniform_int<> unigen;
    std::tr1::variate_generator >gen(engine, unigen);
    std::random_shuffle(vec.begin(), vec.end(), gen);
    

提交回复
热议问题