aboutsummaryrefslogtreecommitdiff
path: root/forth/rand.fs
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2018-09-29 01:02:00 +0200
committerDimitri Sokolyuk <demon@dim13.org>2018-09-29 01:02:00 +0200
commit79cabd5b1c8bcd9f50dc49e77776e713a57dff48 (patch)
tree6eb73857e9c174610839291cf05a02d77fc82b8c /forth/rand.fs
parent247df3bb9d4c89d4e5ff18dcc23ba1c9532f28c0 (diff)
parent110a6411bae421260476eacf6173897c1d1f4b8a (diff)
Merge branch 'master' of dim13.org:elegoo
Diffstat (limited to 'forth/rand.fs')
-rw-r--r--forth/rand.fs17
1 files changed, 17 insertions, 0 deletions
diff --git a/forth/rand.fs b/forth/rand.fs
new file mode 100644
index 0000000..2bd2447
--- /dev/null
+++ b/forth/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) !
+;