Is it possible to have random numbers in commands?

So we already know I have an anarchy world and I want to "troll" some players with a command block with a simple goal.

"One the button is pressed, you will be teleported in a random area, and maybe you can make your base there."

So unlike here, I want to set up a /tp on the command that kinda goes like this:

/tp @p [rand=100000,-100000] 255 [rand=100000,-100000] true

Now I'm thinking of setting the coordinates to a random int without adding a mod or some additional code (because I don't know how to add it in or make one even though I'm a programmer).

Is it possible to set random numbers in a teleportation command in Bedrock Edition?


Solution 1:

Use the /spreadplayers command:

spreadplayers <x: value> <z: value> <spreadDistance: float> <maxRange: float> <victim: target>

X and Z is the center of the range in XZ-plane you wish to start the spread. Spread distance is irrelevant if only randomly placing a single player (it's the minimum distance a player must be placed away from other players) and can be 0. Max range is the maximum distance away from the XZ center the player is to be randomly placed. victim is any selector and in bedrock can apply to any entity, not just players.

As for general randomness for selectors, there isn't a direct syntax to apply random numbers, but you can use the random player selector (@r) anywhere you need an entity selector so long as you specify 'type' with the selector. For example /kill @r[type=zombie] kills a random zombie.