Skip to content

Instantly share code, notes, and snippets.

@Arcensoth
Last active December 8, 2020 05:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arcensoth/042bd7ee628f9ccf74de2c323e715d10 to your computer and use it in GitHub Desktop.
Save Arcensoth/042bd7ee628f9ccf74de2c323e715d10 to your computer and use it in GitHub Desktop.
# 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