From 01c8ca3cbfef3a9b590724b0e48477e4e334df1a Mon Sep 17 00:00:00 2001 From: lynxeyed-atsu Date: Thu, 28 Jun 2012 22:00:19 +0900 Subject: added randomize using linear congruential method --- src/core/arithmetical.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/core/arithmetical.cpp b/src/core/arithmetical.cpp index ad90612..194e10b 100755 --- a/src/core/arithmetical.cpp +++ b/src/core/arithmetical.cpp @@ -9,9 +9,28 @@ void randomSeed(unsigned int seed) return; } +// random algorithm using linear congruential method +unsigned int random(void) +{ + int hi,lo,x; + + x = random_seed; + + if(x == 0)x = 123459876L; + + hi = x / 127773L; + lo = x % 127773L; + x = 16807L * lo - 2836L * hi; + + if(x < 0)x += 0x7FFFFFFFL; + random_seed = x; + + return (x % ((unsigned long int)0x7FFFFFFFL + 1)); + +} // random algorithm using Fibonacci-LFSR -unsigned int random(void) +unsigned int random_LFSR(void) { unsigned int shift_bit; shift_bit = (random_seed & 0x0001) ^ -- cgit v1.2.3