mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-10 03:39:55 +00:00
(cherry picked from commit 8c810e36203b93780cae198a3f7e2fb33ee54b5d) # Conflicts: # apps/openmw/engine.cpp # apps/openmw/mwclass/npc.cpp # components/misc/rng.cpp # components/sceneutil/lightcontroller.cpp # libs/openengine/CMakeLists.txt
29 lines
576 B
C++
29 lines
576 B
C++
#include "rng.hpp"
|
|
#include <cstdlib>
|
|
#include <ctime>
|
|
|
|
namespace Misc
|
|
{
|
|
|
|
void Rng::init()
|
|
{
|
|
std::srand(static_cast<unsigned int>(std::time(NULL)));
|
|
}
|
|
|
|
float Rng::rollProbability()
|
|
{
|
|
return static_cast<float>(std::rand() / (static_cast<double>(RAND_MAX)+1.0));
|
|
}
|
|
|
|
float Rng::rollClosedProbability()
|
|
{
|
|
return static_cast<float>(std::rand() / static_cast<double>(RAND_MAX));
|
|
}
|
|
|
|
int Rng::rollDice(int max)
|
|
{
|
|
return static_cast<int>((std::rand() / (static_cast<double>(RAND_MAX)+1.0)) * (max));
|
|
}
|
|
|
|
}
|