Skip to content

Commit 2343e43

Browse files
committed
Generate random int & double
add old random number and deprecate it to random double
1 parent f4f1afd commit 2343e43

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,25 @@ public enum ScriptActionType {
16441644
ctx.variable("Result").name(),
16451645
new ScriptNumberValue(result)
16461646
);
1647-
})),
1647+
})),
1648+
1649+
RANDOM_NUMBER(builder -> builder.name("Random Number")
1650+
.description("Generates a random number between two other numbers.")
1651+
.icon(Items.HOPPER)
1652+
.category(ScriptActionCategory.NUMBERS)
1653+
.deprecate(RANDOM_DOUBLE)
1654+
.arg("Result", ScriptActionArgumentType.VARIABLE)
1655+
.arg("Min", ScriptActionArgumentType.NUMBER)
1656+
.arg("Max", ScriptActionArgumentType.NUMBER)
1657+
.action(ctx -> {
1658+
double min = ctx.value("Min").asNumber();
1659+
double max = ctx.value("Max").asNumber();
1660+
double result = Math.random() * (max - min) + min;
1661+
ctx.context().setVariable(
1662+
ctx.variable("Result").name(),
1663+
new ScriptNumberValue(result)
1664+
);
1665+
})),
16481666

16491667
REPEAT_FOREVER(builder -> builder.name("RepeatForever")
16501668
.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.")

0 commit comments

Comments
 (0)