Fix random trivia generator

This commit is contained in:
2025-09-17 18:24:37 +02:00
parent a8a18c72da
commit 1f29aff90f
3 changed files with 17 additions and 2 deletions

View File

@@ -49,8 +49,15 @@ std::vector<std::string> scenarioloader_ui::get_random_trivia()
lang = "en";
}
if (triviaData[lang].empty())
{
ErrorLog("No trivia entries found for language \"" + lang + "\".");
return trivia;
}
// select random trivia
int i = Random(0, triviaData[lang].size() - 1);
int i = RandomInt(0, triviaData[lang].size() - 1);
std::string triviaStr = triviaData[lang][i]["text"];
std::string background = triviaData[lang][i]["background"];

View File

@@ -112,6 +112,13 @@ double Random(double a, double b)
return interpolate(a, b, (double)val / Global.random_engine.max());
}
int RandomInt(int min, int max)
{
std::uniform_int_distribution<int> dist(min, max);
return dist(Global.random_engine);
}
double LocalRandom(double a, double b)
{
uint32_t val = Global.local_random_engine();

View File

@@ -60,7 +60,8 @@ inline long Round(double const f)
}
double Random(double a, double b);
double LocalRandom( double a, double b );
int RandomInt(int min, int max);
double LocalRandom(double a, double b);
inline double Random()
{