Random Has Non-Deterministic Behavior

Reporter: RobertBColton  |  Status: closed  |  Last Modified: May 07, 2019, 10:37:52 PM

Ok, so while writing some drawing tests with a fixed random seed, I ran into this problem.

random_set_seed(236732942);
for (i = 0; i < 3; i += 1) {
    show_message(string(irandom(10)));
}

This always produces 3, 5, 9 in GM8 for me, but in ENIGMA the second two numbers are not correct. This has to do with the fact that the next seed chosen by ENIGMA is not based on the current seed, making the behavior totally non-deterministic.

I get the same results in GMSv1.4 except the numbers are always 1, 8, 8.

@RemoveRusky correctly found the issue for me, which is here:

enigma::Random_Seed = mtrandom32();
JoshDreamland  
The random() regression did show up at some point and is now being picked up by the test harness. Fortunately, this is non-fatal (for now), as the added failures are not affecting the game's return code. This would mean that our tests are broken, but random() is presently the only test suite using gtest_expect_ rather than gtest_assert_. So we can probably fix both in one go.
RobertBColton  

Ok, what you told me over chats the other day is in fact correct. I made the following little test in GM8.1 and I can see that calling a random function does change the seed, and even better, we are able to obtain that seed each time. The seed is also deterministic just like the random numbers generated from the initial seed. The seeds that GM8.1 gives me are 1493992007, 2057512804, -526428939.

random_set_seed(236732942);
for (i = 0; i < 3; i += 1) {
    irandom(10);
    show_message(string(random_get_seed()));
}

If I use the seed as the Mersenne seed to pick the new seed, I do get deterministic random numbers, but they are not the same as GM. I get 3,7,5 where GM gives me 3,5,9.

    mtrandom_seed(enigma::Random_Seed);
    enigma::Random_Seed = mtrandom32();

RobertBColton  

Ok, another little test. I plugged in all of the seeds manually and managed to get the correct number sequence same as GM8.1 which is 3,5,9,9,2. So this suggests there's nothing wrong with our random generation, just the selection of the next seed.

random_set_seed(236732942);
show_message(string(irandom(10))); // 3
random_set_seed(1493992007);
show_message(string(irandom(10))); // 5
random_set_seed(2057512804);
show_message(string(irandom(10))); // 9
random_set_seed(-526428939);
show_message(string(irandom(10))); // 9
random_set_seed(-627901238);
show_message(string(irandom(10))); // 2

RobertBColton  

Closing as resolved by #1706 with a CI test!
Please sign in to post comments, or you can view this issue on GitHub.