added reset_seed
This commit is contained in:
1 parent
ece43b6213
commit
eab24f7896
6 files changed
+21
-2
No files matched your search
@@ -239,6 +239,11 @@ map(range(10), bool(rand(2))) => [false, false, true, false, false, false, true,
|
|||||||
map(range(10), str('%.1f',rand(_))) => [0.0, 0.4, 0.6, 1.9, 2.8, 3.8, 5.3, 2.2, 1.6, 5.6]
|
map(range(10), str('%.1f',rand(_))) => [0.0, 0.4, 0.6, 1.9, 2.8, 3.8, 5.3, 2.2, 1.6, 5.6]
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
## `reset_seed(seed)`
|
||||||
|
|
||||||
|
Resets the sequence of the randomizer used by `rand` for this seed to its initial state. Returns a boolean value
|
||||||
|
indicating if the given seed has been used or not.
|
||||||
|
|
||||||
### `perlin(x), perlin(x, y), perlin(x, y, z), perlin(x, y, z, seed)`
|
### `perlin(x), perlin(x, y), perlin(x, y, z), perlin(x, y, z, seed)`
|
||||||
|
|
||||||
returns a noise value from `0.0` to `1.0` (roughly) for 1, 2 or 3 dimensional coordinate. The default seed it samples
|
returns a noise value from `0.0` to `1.0` (roughly) for 1, 2 or 3 dimensional coordinate. The default seed it samples
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ reduce
|
|||||||
relu
|
relu
|
||||||
replace
|
replace
|
||||||
replace_first
|
replace_first
|
||||||
|
reset_seed
|
||||||
return
|
return
|
||||||
round
|
round
|
||||||
sec
|
sec
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
<Keywords name="Folders in comment, middle"></Keywords>
|
<Keywords name="Folders in comment, middle"></Keywords>
|
||||||
<Keywords name="Folders in comment, close"></Keywords>
|
<Keywords name="Folders in comment, close"></Keywords>
|
||||||
<Keywords name="Keywords1">
|
<Keywords name="Keywords1">
|
||||||
not fact rand
|
not fact rand reset_seed
|
||||||
sin cos tan asin acos atan atan2 sinh cosh tanh sec csc sech csch cot acot coth asinh acosh atanh
|
sin cos tan asin acos atan atan2 sinh cosh tanh sec csc sech csch cot acot coth asinh acosh atanh
|
||||||
rad deg
|
rad deg
|
||||||
log log10 log1p
|
log log10 log1p
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
|
|
||||||
var undef vars if loop map filter first all c_for for while reduce continue break
|
var undef vars if loop map filter first all c_for for while reduce continue break
|
||||||
|
|
||||||
import call outer type hash_code bool number str length rand sleep time profile_expr lower upper title replace replace_first
|
import call outer type hash_code bool number str length sleep time profile_expr lower upper title replace replace_first
|
||||||
</Keywords>
|
</Keywords>
|
||||||
<Keywords name="Keywords2">
|
<Keywords name="Keywords2">
|
||||||
block pos pos_offset solid air liquid flammable
|
block pos pos_offset solid air liquid flammable
|
||||||
|
|||||||
@@ -313,6 +313,11 @@ public class Expression
|
|||||||
addUnaryFunction(name, (v) -> new NumericValue(fun.apply(NumericValue.asNumber(v).getDouble())));
|
addUnaryFunction(name, (v) -> new NumericValue(fun.apply(NumericValue.asNumber(v).getDouble())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addMathematicalUnaryIntFunction(String name, Function<Double, Long> fun)
|
||||||
|
{
|
||||||
|
addUnaryFunction(name, (v) -> new NumericValue(fun.apply(NumericValue.asNumber(v).getDouble())));
|
||||||
|
}
|
||||||
|
|
||||||
public void addMathematicalBinaryFunction(String name, BiFunction<Double, Double, Double> fun)
|
public void addMathematicalBinaryFunction(String name, BiFunction<Double, Double, Double> fun)
|
||||||
{
|
{
|
||||||
addBinaryFunction(name, (w, v) ->
|
addBinaryFunction(name, (w, v) ->
|
||||||
|
|||||||
@@ -42,6 +42,10 @@ public abstract class ScriptHost
|
|||||||
return randomizers.computeIfAbsent(aLong, Random::new);
|
return randomizers.computeIfAbsent(aLong, Random::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean resetRandom(long aLong) {
|
||||||
|
return randomizers.remove(aLong) != null;
|
||||||
|
}
|
||||||
|
|
||||||
public static class ModuleData
|
public static class ModuleData
|
||||||
{
|
{
|
||||||
Module parent;
|
Module parent;
|
||||||
|
|||||||
@@ -210,6 +210,10 @@ public class Sys {
|
|||||||
Value retval = new NumericValue(NumericValue.asNumber(argument).getDouble()*randomizer.nextDouble());
|
Value retval = new NumericValue(NumericValue.asNumber(argument).getDouble()*randomizer.nextDouble());
|
||||||
return (cc, tt) -> retval;
|
return (cc, tt) -> retval;
|
||||||
});
|
});
|
||||||
|
expression.addLazyFunction("reset_seed", 1, (c, t, lv) -> {
|
||||||
|
boolean gotIt = c.host.resetRandom(NumericValue.asNumber(lv.get(0).evalValue(c)).getLong());
|
||||||
|
return gotIt?LazyValue.TRUE:LazyValue.FALSE;
|
||||||
|
});
|
||||||
|
|
||||||
expression.addLazyFunction("perlin", -1, (c, t, lv) ->
|
expression.addLazyFunction("perlin", -1, (c, t, lv) ->
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user