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:
parent
3f28634d1f
commit
2cfc4c0286
1 changed files with 3 additions and 3 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue