projects
/
vvhitespace
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
2da7419
)
Replaced RNG with Xorshift implementation from Wikipedia.
author
Daniel Neshyba-Rowe
<rowedanielp@gmail.com>
Sat, 11 Jan 2020 02:45:07 +0000
(
02:45
+0000)
committer
Daniel Neshyba-Rowe
<rowedanielp@gmail.com>
Sat, 11 Jan 2020 02:45:07 +0000
(
02:45
+0000)
stdlib/math.pvvs
patch
|
blob
|
blame
|
history
diff --git
a/stdlib/math.pvvs
b/stdlib/math.pvvs
index
742522e
..
a72203f
100644
(file)
--- a/
stdlib/math.pvvs
+++ b/
stdlib/math.pvvs
@@
-5,34
+5,44
@@
@ Name:
@ random (10000)
@ Description:
@ Name:
@ random (10000)
@ Description:
-@ Returns a kinda-random number.
-@ Before using for the first time, seed heap[0] with a value.
+@ Returns a pseudo-random number.
+@ Before using for the first time, seed heap[0] with a non-zero value.
+@ This PRNG was taken from: https://en.wikipedia.org/wiki/Xorshift
@ Call Stack:
@ empty
@ Return Stack:
@ random number <-- TOS
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ Call Stack:
@ empty
@ Return Stack:
@ random number <-- TOS
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+#include <logic.pvvs>
NSSVTSSSSN | Mark: 10000 (random)
NSSVTSSSSN | Mark: 10000 (random)
-@
Generate the next seed value
+@
Fetch seed from heap[0].
SSSSN | PUSH 0 (ptr)
TTT | LOAD
SSSSN | PUSH 0 (ptr)
TTT | LOAD
-SSSTSSSSSTTTSSSTTSSTSSTTTSSTTSTTSTN | PUSH 1103515245
-TSSN | MULTIPLY
-SSSTTSSSSSSTTTSSTN | PUSH 12345
-TSSS | ADD
-@ Store the next seed value but keep a copy on the stack.
+@ Set TOS ^= TOS << 13
+SNS | DUP
+SSSTTSTN | PUSH +13
+NSTTSTTSTN | JSR > 101101 (lshift)
+NSTTSTSTTN | JSR > 101011 (xor)
+
+@ Set TOS ^= TOS >> 7
+SNS | DUP
+SSSTTTN | PUSH +7
+NSTTSTTSSN | JSR > 101100 (rshift)
+NSTTSTSTTN | JSR > 101011 (xor)
+
+@ Set TOS ^= TOS << 17
+SNS | DUP
+SSSTSSSTN | PUSH +17
+NSTTSTTSTN | JSR > 101101 (lshift)
+NSTTSTSTTN | JSR > 101011 (xor)
+
+@ Store a copy of the new seed at heap[0] and return.
SNS | DUP
SSSSN | PUSH 0 (ptr)
SNT | SWAP
TTS | STORE
SNS | DUP
SSSSN | PUSH 0 (ptr)
SNT | SWAP
TTS | STORE
-
-@ Calculate the random number and return.
-SSSTSSSSSSSSSSSSSSSSN | PUSH 65536
-TSTS | DIVIDE
-SSSTSSSSSSSSSSSSSSSN | PUSH 32768
-TSTT | MODULO
NTN | RTS
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
NTN | RTS
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@