Using boost::random and getting same sequence of numbers

前端 未结 6 721
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-19 19:04

I have the following code:

Class B {

void generator()
{
    // creating random number generator
    boost::mt19937 randgen(static_cast(s         


        
6条回答
  •  渐次进展
    2020-12-19 19:53

    First Thoughts

    On unix you could try reading some bytes from /dev/random or /dev/urandom for the seed. You could also try using a combination of time(0) + pid + static counter (or pseudo-random sequence).

    I believe on windows, you can use QueryPerformanceCounter to get the value of the high performance timer register.

    Another thought:

    You could declare your mt19937 prng as a static or global so you never lose its state.

    A third thought:

    You wish to "execute the above code multiple times in rapid succession to produce multiple graphs" pass in a graph index. (e.g. genGraph(int graphIndex) and combine this (add, xor, etc) with the output of time(0). boost::mt19937 randgen(static_cast(std::time(0) + graphIndex));

提交回复
热议问题