aboutsummaryrefslogtreecommitdiff
path: root/forth/elegoo/rand.fs
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2018-09-21 21:59:17 +0200
committerDimitri Sokolyuk <demon@dim13.org>2018-09-21 21:59:17 +0200
commit2f83a0bea9da444e3d70569eba3d6847ca02be03 (patch)
tree20163bbd478f40679d22f5e964aef94c688639f0 /forth/elegoo/rand.fs
parent125127ee67891e1813164e20aa848a80b9d2f2a0 (diff)
...
Diffstat (limited to 'forth/elegoo/rand.fs')
-rw-r--r--forth/elegoo/rand.fs17
1 files changed, 17 insertions, 0 deletions
diff --git a/forth/elegoo/rand.fs b/forth/elegoo/rand.fs
new file mode 100644
index 0000000..2bd2447
--- /dev/null
+++ b/forth/elegoo/rand.fs
@@ -0,0 +1,17 @@
+\ Fast Random Number Generator algorithm by George Marsaglia "Xorshift RNGs"
+
+-rnd
+marker -rnd
+
+: xorshift ( n -- n )
+ dup #13 lshift xor
+ dup #17 rshift xor
+ dup #5 lshift xor
+;
+
+variable (rnd) \ seed
+ticks (rnd) ! \ initialize seed
+
+: rnd ( -- n )
+ (rnd) @ xorshift dup (rnd) !
+;