Skip to content

Instantly share code, notes, and snippets.

@misode
Last active May 15, 2021 00:40
Show Gist options
  • Save misode/39b5f59ed668637aecaae49d8d041171 to your computer and use it in GitHub Desktop.
Save misode/39b5f59ed668637aecaae49d8d041171 to your computer and use it in GitHub Desktop.

Generating pseudo random numbers

You need to run some commands once (or on every /reload).

scoreboard objectives add random dummy
execute unless score seed random matches -2147483648.. run scoreboard players set seed random 731031
scoreboard players set mult random 1664525
scoreboard players set incr random 1013904223
scoreboard players set #16 random 16

Whenever you need a random output between 0 and a max number, you can call this function. It will store a random number from 0 (inclusive) to max (exclusive) in result random.

scoreboard players operation seed random *= mult random
scoreboard players operation seed random += incr random
scoreboard players operation result random = seed random
scoreboard players operation result random /= #16 random
scoreboard players operation result random %= max random
@logicguy1
Copy link

you shud add a prefix to ur fakeplayers like a # so fx
scoreboard players set #mult random 1664525
scoreboard players set #incr random 1013904223

@misode
Copy link
Author

misode commented Oct 26, 2019

@logicguy1 That is actually not necessary since there are no players on the scoreboard objective.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment