mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2024-08-13 17:03:47 -04:00
677c4845f6
* WiiU: fix more scaling issues * Wii U: batch depth reads * Wii U: remove file buffering Doesn't seem to to do much anymore * Remove "missing_gcc_functions.c" to avoid conflicts * Wii U: Fix random_device usage random_device will always be seeded with a constant seed and will return the same number sequence every time * Wii U: Improve software keyboard * Wii U: Fix console input text width
34 lines
952 B
C++
34 lines
952 B
C++
#include "random.hpp"
|
|
|
|
#include <random>
|
|
|
|
static bool init = false;
|
|
static std::mt19937_64 generator;
|
|
|
|
//Initialize with seed specified
|
|
void Random_Init(uint32_t seed) {
|
|
init = true;
|
|
generator = std::mt19937_64{seed};
|
|
}
|
|
|
|
//Returns a random integer in range [min, max-1]
|
|
uint32_t Random(int min, int max) {
|
|
if (!init) {
|
|
//No seed given, get a random number from device to seed
|
|
#if !defined(__SWITCH__) && !defined(__WIIU__)
|
|
const auto seed = static_cast<uint32_t>(std::random_device{}());
|
|
#else
|
|
uint32_t seed = static_cast<uint32_t>(std::hash<std::string>{}(std::to_string(rand())));
|
|
#endif
|
|
Random_Init(seed);
|
|
}
|
|
std::uniform_int_distribution<uint32_t> distribution(min, max-1);
|
|
return distribution(generator);
|
|
}
|
|
|
|
//Returns a random floating point number in [0.0, 1.0]
|
|
double RandomDouble() {
|
|
std::uniform_real_distribution<double> distribution(0.0, 1.0);
|
|
return distribution(generator);
|
|
}
|