1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-29 22:45:34 +00:00

script Random() command now returns correct range.

This commit is contained in:
dteviot 2015-03-21 18:21:01 +13:00
parent 3f28634d1f
commit 2cfc4c0286

View file

@ -12,6 +12,8 @@
#include "runtime.hpp"
#include "defines.hpp"
#include <openengine/misc/rng.hpp>
namespace Interpreter
{
inline std::string formatMessage (const std::string& message, Runtime& runtime)
@ -140,15 +142,13 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
double r = static_cast<double> (std::rand()) / RAND_MAX; // [0, 1)
Type_Integer limit = runtime[0].mInteger;
if (limit<0)
throw std::runtime_error (
"random: argument out of range (Don't be so negative!)");
Type_Integer value = static_cast<Type_Integer> (r*limit); // [o, limit)
Type_Integer value = OEngine::Misc::Rng::rollDice(limit); // [o, limit)
runtime[0].mInteger = value;
}