aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlynxeyed-atsu <lynxeyed@xj9.so-net.ne.jp>2012-06-28 22:00:19 +0900
committerlynxeyed-atsu <lynxeyed@xj9.so-net.ne.jp>2012-06-28 22:00:19 +0900
commit01c8ca3cbfef3a9b590724b0e48477e4e334df1a (patch)
tree32fd7993e202eb1f263f1f343dd0af70f1a53f0a /src
parent6954aaeccfaf962c31ef5f1c9a5d62b14df1537f (diff)
added randomize using linear congruential method
Diffstat (limited to 'src')
-rwxr-xr-xsrc/core/arithmetical.cpp21
1 files changed, 20 insertions, 1 deletions
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) ^