Skip to content

Commit e4e5860

Browse files
committed
Generate random int & double
add old random number and deprecate it to random double
1 parent 2434666 commit e4e5860

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/main/java/io/github/techstreet/dfscript/script/action/ScriptActionType.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,24 @@ public enum ScriptActionType {
16411641
);
16421642
})),
16431643

1644+
RANDOM_NUMBER(builder -> builder.name("Random Number")
1645+
.description("Generates a random number between two other numbers.")
1646+
.icon(Items.HOPPER)
1647+
.category(ScriptActionCategory.NUMBERS)
1648+
.deprecate(RANDOM_DOUBLE)
1649+
.arg("Result", ScriptActionArgumentType.VARIABLE)
1650+
.arg("Min", ScriptActionArgumentType.NUMBER)
1651+
.arg("Max", ScriptActionArgumentType.NUMBER)
1652+
.action(ctx -> {
1653+
double min = ctx.value("Min").asNumber();
1654+
double max = ctx.value("Max").asNumber();
1655+
double result = Math.random() * (max - min) + min;
1656+
ctx.context().setVariable(
1657+
ctx.variable("Result").name(),
1658+
new ScriptNumberValue(result)
1659+
);
1660+
})),
1661+
16441662
REPEAT_FOREVER(builder -> builder.name("RepeatForever")
16451663
.description("Repeats for eternity.\nMake sure to have a Stop Repetition, Stop Codeline or Wait somewhere in the code!\nThere's a lagslayer for the repetition actions.\nIt activates after 100000 iterations with no Wait.")
16461664
.icon(Items.GOLD_INGOT)

0 commit comments

Comments
 (0)