added reset_seed

This commit is contained in:
gnembon committed 2021-03-12 06:11:55 -04:00
1 parent ece43b6213
commit eab24f7896
6 files changed
+21 -2

No files matched your search

+5
View File
@@ -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]
</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)`
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
replace
replace_first
reset_seed
return
round
sec
@@ -25,7 +25,7 @@
<Keywords name="Folders in comment, middle"></Keywords>
<Keywords name="Folders in comment, close"></Keywords>
<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
rad deg
log log10 log1p
@@ -46,7 +46,7 @@
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 name="Keywords2">
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())));
}
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)
{
addBinaryFunction(name, (w, v) ->
@@ -42,6 +42,10 @@ public abstract class ScriptHost
return randomizers.computeIfAbsent(aLong, Random::new);
}
public boolean resetRandom(long aLong) {
return randomizers.remove(aLong) != null;
}
public static class ModuleData
{
Module parent;
@@ -210,6 +210,10 @@ public class Sys {
Value retval = new NumericValue(NumericValue.asNumber(argument).getDouble()*randomizer.nextDouble());
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) ->
{