Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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