mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-21 21:24:58 +01:00
fix: whole-number bounds of Random() give a real number again (#416)
* fix: whole-number bounds of Random() give a real number againee3af0bf(#99, in 26.05.2) renamed RandomInt to an overload, Random(int, int). The calls with whole-number bounds that expect a real number in between took the overload and draw whole numbers since: - wheel flats given with P0 happen to 1 vehicle in 101 (before: none), the random part of a flat is a whole number of millimetres; - the chance of truck hunting is h/101 instead of h/100; - the wind starts with a whole azimuth, speed and rates of change, and its direction changes in whole degrees per second; - the tachometer below 5 km/h jumps to whole numbers. The whole-number draw is RandomInt again, keeping the shared engine and the swap of inverted bounds; the loading screen's trivia use it. Those calls take the real Random() again, as up to 26.05.1. * RandomInt: the comment says what it draws and why it has a name of its own The comment put the bug on the overloading. It was in the calls that pass whole-number bounds and expect a real number; the separate name keeps them on Random(double, double). * fix: RandomInt draws from the local engine, as up to 26.05.1 from one of its own From the review of #416:ee3af0bfmoved RandomInt from an engine of its own (std::mt19937 seeded by std::random_device) to Global.random_engine, the engine of the run's seed, and only the name was taken back here. Its one caller draws the trivia of the loading screen, in init_modes, before a network client gets the seed of the session in server_hello: the server's engine was then one draw ahead of the client's, and with a fixed randomseed the trivia was the same on every start. It is drawn from Global.local_random_engine now, the engine of what one machine shows, seeded from a true random source in init_modes before the loader is made. The test of the same seed checks the shared engine with Random() and the local one with RandomInt(); a new test checks that RandomInt() doesn't move the engine of the run's seed. --------- Co-authored-by: maj00r <maj00r@host>
This commit is contained in:
@@ -88,7 +88,7 @@ std::vector<std::string> scenarioloader_ui::get_random_trivia()
|
||||
json triviaData = json::parse(fileContent);
|
||||
|
||||
// select random
|
||||
int i = Random(0, static_cast<int>(triviaData.size()) - 1);
|
||||
int i = RandomInt(0, static_cast<int>(triviaData.size()) - 1);
|
||||
std::string triviaStr = triviaData[i]["text"];
|
||||
std::string background = triviaData[i]["background"];
|
||||
if (triviaData[i].contains("scenery"))
|
||||
|
||||
Reference in New Issue
Block a user