#include "functionrandom.h" #include "gamestate.h" #include #ifdef WIN32 #define random() rand() #endif FunctionRandom::FunctionRandom() { } FunctionRandom::~FunctionRandom() { } void FunctionRandom::call( class GameState &gState ) { Variable vHigh = gState.popDeref(); Variable vLow = gState.popDeref(); if( vHigh.getType() != vLow.getType() ) throw Bu::ExceptionBase("Different types in random!"); double dRand = random()/(double)(RAND_MAX-1); if( vLow.getType() == Variable::tInt ) { gState.push( Variable( (int64_t)( (dRand*(vHigh.getInt()-vLow.getInt()+1ll))+vLow.getInt() ) ) ); } else if( vLow.getType() == Variable::tFloat ) { gState.push( Variable( (double)( (dRand*(vHigh.getFloat()-vLow.getFloat()))+vLow.getFloat() ) ) ); } }