Minecraft:Commands/random: Difference between revisions
More actions
imported>LauraFii m Undo revision 3516307 by ~2026-EmeraldStoneCamel8319 (talk) test edit |
Fix template calls: add MC/ prefix |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
{{ | {{MC/Exclusive|java}} | ||
{{Infobox command | {{Infobox command | ||
|name=random | |name=random | ||
| Line 7: | Line 7: | ||
}} | }} | ||
Generates a random integer, or controls | Generates a random integer, or controls random sequences in the world. | ||
== Syntax == | == Syntax == | ||
| Line 29: | Line 29: | ||
: Removes and re-creates a random sequence with the specified settings instead of the settings of the world. If the sequence does not exist, it is just created. | : Removes and re-creates a random sequence with the specified settings instead of the settings of the world. If the sequence does not exist, it is just created. | ||
{{ | {{MC/See also|Random sequence format#Usage}} | ||
== Arguments == | == Arguments == | ||
| Line 37: | Line 37: | ||
: If it is <code>value</code>, the result is displayed in chat only to the player executing the command. If <code>roll</code>, the result is broadcasted to all players. | : If it is <code>value</code>, the result is displayed in chat only to the player executing the command. If <code>roll</code>, the result is broadcasted to all players. | ||
{{ | {{MC/Argument|range|int_range}} | ||
: Specifies the range to pick the random number from. The size of the range (calculated by <code>max - min + 1</code>) should be between 2 and 2147483646. | : Specifies the range to pick the random number from. The size of the range (calculated by <code>max - min + 1</code>) should be between 2 and 2147483646. | ||
: {{ | : {{MC/Arg desc|je=int_range}} | ||
{{ | {{MC/Argument|sequence|resource_location}} | ||
: Specifies the | : Specifies the resource location of a random sequence to sample or reset. | ||
: If there's no sequence with the specified | : If there's no sequence with the specified resource location, it is created. | ||
: {{ | : {{MC/Arg desc|je=resource_location}} | ||
{{ | {{MC/Argument|seed|int}} | ||
: The salt value. | : The salt value. | ||
: {{ | : {{MC/Arg desc|je=integer}} | ||
{{ | {{MC/Argument|includeWorldSeed|bool}} | ||
: Whether to incorporate the world seed value with the specified <code><seed></code> when seeding a random sequence. If not specified, defaults to <code>true</code>. | : Whether to incorporate the world seed value with the specified <code><seed></code> when seeding a random sequence. If not specified, defaults to <code>true</code>. | ||
: {{ | : {{MC/Arg desc|je=bool}} | ||
{{ | {{MC/Argument|includeSequenceId|bool}} | ||
:Whether to incorporate the hash of the ID with the specified <code><seed></code> when seeding a random sequence. If not specified, defaults to <code>true</code>. | :Whether to incorporate the hash of the ID with the specified <code><seed></code> when seeding a random sequence. If not specified, defaults to <code>true</code>. | ||
: {{ | : {{MC/Arg desc|je=bool}} | ||
== Examples == | == Examples == | ||
{{ | {{MC/Code|/random roll 1..5}} | ||
Rolls a random number between 1 and 5 and writes it in chat | Rolls a random number between 1 and 5 and writes it in chat | ||
{{ | {{MC/Code|execute store result score @p random_number run random value 1..10}} | ||
Generates a random number between 1 and 10 and stores it in a scoreboard called {{ | Generates a random number between 1 and 10 and stores it in a scoreboard called {{MC/Code|random_number}} for the nearest player | ||
{{ | {{MC/Code|/execute store result score player random_number run random value 1..3}} | ||
{{code|/tellraw @a [{text:"Rolled number "},{"score": {"name": "player", "objective": "random_number"} }]}} | {{code|/tellraw @a [{text:"Rolled number "},{"score": {"name": "player", "objective": "random_number"} }]}} | ||
| Line 76: | Line 76: | ||
{{Result table|onlyje=1}} | {{Result table|onlyje=1}} | ||
{{Result table|the arguments are not specified correctly|unparseable}} | {{Result table|the arguments are not specified correctly|unparseable}} | ||
{{Result table|cmd=/random (value{{!}}roll) ...|{{Cd|<range>}}range is less than 2 or greater than 2147483646|fail}} | {{Result table|cmd=/random (value{{!}}roll) ...|{{MC/Cd|<range>}}range is less than 2 or greater than 2147483646|fail}} | ||
{{Result table|cmd=|success}} | {{Result table|cmd=|success}} | ||
{{Result table}} | {{Result table}} | ||
| Line 82: | Line 82: | ||
== Output == | == Output == | ||
{{Output table}} | {{MC/Output table}} | ||
{{Output table|edition=je|On fail|0|0|0}} | {{MC/Output table|edition=je|On fail|0|0|0}} | ||
{{Output table|cmd=/random (value{{!}}roll) ... |On success|1|1|the obtained random value}} | {{Output table|cmd=/random (value{{!}}roll) ... |On success|1|1|the obtained random value}} | ||
{{Output table|cmd=/random reset <sequence> ... |On success|1|1|1}} | {{MC/Output table|cmd=/random reset <sequence> ... |On success|1|1|1}} | ||
{{Output table|cmd=/random reset * ... |On success|1|1|the number of random sequences currently in the world}} | {{MC/Output table|cmd=/random reset * ... |On success|1|1|the number of random sequences currently in the world}} | ||
{{Output table}} | {{MC/Output table}} | ||
== History == | == History == | ||
{{HistoryTable | {{HistoryTable | ||
|{{HistoryLine|Java}} | |{{MC/HistoryLine|Java}} | ||
|{{HistoryLine||1.20.2|dev=23w31a|Added {{ | |{{HistoryLine||1.20.2|dev=23w31a|Added {{MC/Cd|/random}}.}} | ||
}} | }} | ||
== Navigation == | == Navigation == | ||
{{Navbox commands}} | {{MC/Navbox commands}} | ||
de:Befehl/random | |||
ja:コマンド/random | |||
pt:Comandos/random | |||
ru:Команды консоли/random | |||
zh:命令/random | |||
Latest revision as of 20:12, 9 April 2026
Script error: No such module "Exclusive". Template:Infobox command
Generates a random integer, or controls random sequences in the world.
Syntax
random (value|roll) <range>
- Outputs a random integer.
- Range is given by two integers separated by two periods where the first given number must always be smaller than the second given number.
random (value|roll) <range> <sequence>
- Samples a random integer from the specified random sequence. If the sequence does not exist, it is created with the random sequence settings of the world.
random reset *
- Removes all the random sequences in the world. A random sequence is created with the settings of the world when called by a loot table.
random reset * <seed> [<includeWorldSeed>] [<includeSequenceId>]
- Removes all the random sequences in the world, and sets the random sequence settings of the world. The setting of the world is
0,true,true, if having not executed/random reset * ...command in the world.
random reset <sequence>
- Removes and re-creates a random sequence with the settings of the world. If the sequence does not exist, it is just created.
random reset <sequence> [<seed>] [<includeWorldSeed>] [<includeSequenceId>]
- Removes and re-creates a random sequence with the specified settings instead of the settings of the world. If the sequence does not exist, it is just created.
{{#vardefine:params|0 }}Template:Hatnote
Arguments
- Whether or not to notify other players of the results when extracting random numbers.
- If it is
value, the result is displayed in chat only to the player executing the command. Ifroll, the result is broadcasted to all players.
<range>: int_range
- Specifies the range to pick the random number from. The size of the range (calculated by
max - min + 1) should be between 2 and 2147483646. - {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|int_range}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<sequence>: resource_location
- Specifies the resource location of a random sequence to sample or reset.
- If there's no sequence with the specified resource location, it is created.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|resource_location}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<seed>: int
- The salt value.
- {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|integer}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<includeWorldSeed>: bool
- Whether to incorporate the world seed value with the specified
<seed>when seeding a random sequence. If not specified, defaults totrue. - {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|bool}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
<includeSequenceId>: bool
- Whether to incorporate the hash of the ID with the specified
<seed>when seeding a random sequence. If not specified, defaults totrue. - {{#vardefine:onlyje|}}{{#vardefine:onlybe| Template:IN,}}{{#vardefine:je-arg|bool}}{{#vardefine:be-arg|}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Examples
/random roll 1..5
Rolls a random number between 1 and 5 and writes it in chat
execute store result score @p random_number run random value 1..10
Generates a random number between 1 and 10 and stores it in a scoreboard called random_number for the nearest player
/execute store result score player random_number run random value 1..3
Generates a number between 1 and 3 and displays it with message "Rolled number <rolled number>"
Result
Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table
Output
{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-table-lines|-2}}{{#vardefine:output-table-lines-now|}}{{#vardefine:command-num-now|}}{{#vardefine:command-line-now|}}{{#vardefine:commands-num|}}{{#vardefine:output-edition-num-now|}}{{#vardefine:output-edition-line-now|}}{{#vardefine:output-editions-num|}}{{#vardefine:je-outputs-dis|}}
{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On fail}}{{#vardefine:output1-{{#var:output-table-lines}}|0}}{{#vardefine:output2-{{#var:output-table-lines}}|0}}{{#vardefine:output3-{{#var:output-table-lines}}|0}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-editions-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-edition-{{#var:output-editions-num}}|je}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|1}}
Template:Output table
{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On success}}{{#vardefine:output1-{{#var:output-table-lines}}|1}}{{#vardefine:output2-{{#var:output-table-lines}}|1}}{{#vardefine:output3-{{#var:output-table-lines}}|1}}{{#vardefine:commands-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:command-{{#var:commands-num}}|/random reset <sequence> ...}}{{#vardefine:command-row-{{#var:commands-num}}|1}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}}
{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On success}}{{#vardefine:output1-{{#var:output-table-lines}}|1}}{{#vardefine:output2-{{#var:output-table-lines}}|1}}{{#vardefine:output3-{{#var:output-table-lines}}|the number of random sequences currently in the world}}{{#vardefine:commands-num|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:command-{{#var:commands-num}}|/random reset * ...}}{{#vardefine:command-row-{{#var:commands-num}}|1}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}}
{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-table-lines|-2}}{{#vardefine:output-table-lines-now|}}{{#vardefine:command-num-now|}}{{#vardefine:command-line-now|}}{{#vardefine:commands-num|}}{{#vardefine:output-edition-num-now|}}{{#vardefine:output-edition-line-now|}}{{#vardefine:output-editions-num|}}{{#vardefine:je-outputs-dis|}}
History
de:Befehl/random ja:コマンド/random pt:Comandos/random ru:Команды консоли/random zh:命令/random