Last active
December 8, 2020 05:06
-
-
Save Arcensoth/042bd7ee628f9ccf74de2c323e715d10 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Advance the given PRNG seed, optionally using salt to diverge into a new stream. | |
# multiplier = 1103515245 | |
# increment = 12345 | |
# truncate = 16 | |
# start with the seed | |
scoreboard players operation $result foo._out = $seed foo._in | |
# mutate the seed by multiplying by the salt | |
# (a value of 1 will have no effect and will produce the same result as standard LCG) | |
scoreboard players operation $result foo._out *= $salt foo._in | |
# multiply by the constant multiplier | |
scoreboard players operation $result foo._out *= $prng.multiplier foo._const | |
# add the constant increment | |
scoreboard players operation $result foo._out += $prng.increment foo._const | |
# module is done naturally by scoreboard overflow | |
# drop a few lower bits to improve randomness | |
scoreboard players operation $result foo._out /= $prng.truncate foo._const |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment