From 8b9a15a755ebc6681ff6be808615e375cb567080 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 3 Jan 2012 00:08:48 -0700 Subject: New functions, fixes, and a working bloodfields. --- src/functionrandom.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/functionrandom.cpp') diff --git a/src/functionrandom.cpp b/src/functionrandom.cpp index 2665a14..ec302b3 100644 --- a/src/functionrandom.cpp +++ b/src/functionrandom.cpp @@ -20,10 +20,17 @@ void FunctionRandom::call( class GameState &gState ) 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)( - (random()%(vHigh.getInt()-vLow.getInt()+1ll))+vLow.getInt() + (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() ) ) ); } } -- cgit v1.2.3