summaryrefslogtreecommitdiff
path: root/src/functionrandom.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/functionrandom.cpp')
-rw-r--r--src/functionrandom.cpp9
1 files changed, 8 insertions, 1 deletions
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 )
20 if( vHigh.getType() != vLow.getType() ) 20 if( vHigh.getType() != vLow.getType() )
21 throw Bu::ExceptionBase("Different types in random!"); 21 throw Bu::ExceptionBase("Different types in random!");
22 22
23 double dRand = random()/(double)(RAND_MAX-1);
23 if( vLow.getType() == Variable::tInt ) 24 if( vLow.getType() == Variable::tInt )
24 { 25 {
25 gState.push( Variable( (int64_t)( 26 gState.push( Variable( (int64_t)(
26 (random()%(vHigh.getInt()-vLow.getInt()+1ll))+vLow.getInt() 27 (dRand*(vHigh.getInt()-vLow.getInt()+1ll))+vLow.getInt()
28 ) ) );
29 }
30 else if( vLow.getType() == Variable::tFloat )
31 {
32 gState.push( Variable( (double)(
33 (dRand*(vHigh.getFloat()-vLow.getFloat()))+vLow.getFloat()
27 ) ) ); 34 ) ) );
28 } 35 }
29} 36}