vendredi 1 mai 2020

Where should I put my random number generation to get random results?

I have a nested system as described in the pseudocode below (part of a random weighted majority algorithm):

function1() { 
    //for 100 iterations:
        function2()
        // grab logistics
}
function2() {
    // create a random seed/generator
    random_device rd;
    mt19937 gen(rd);
    //for 1000 iterations:
        function3(gen);
}

function3(gen) {
    // grab number from uniform_real_distribution using gen
    // then use that number against differing weights
    // such that higher weight gets more territory in the uniform distribution for its desired outcome
    // that is in a system with weights (1, 1/2) distributed over a uniform distribution (0,1)
    // outcome of weight 1 happens if dist lands (0,.6666) and outcome of weight 2 if dist lands (.6666, 1)
}

In the above example, uniform_real_distribution generates what appears to be random numbers, but function1 always ends up with the exact same result.

However, when I run this function1 will always get the same exact results in every iteration, even though the other two functions are supposed to be random. Even worse, if I change the generator from something like mt19937 to ranlux48, the system will get the exact same results each iteration, but that exact result will be different from the one the mt19937 got, which means everything I'm doing is not random-- only dependent on the generator.

I need guidance on how to fix this such that I have truly random results.

Where should I place gen and rd? Should I even use a uniform real distribution?

If I create gen in function3 every time it is called, I also still get non-random results, in fact uniform_real_distribution generates the exact same value every time




Aucun commentaire:

Enregistrer un commentaire