MathematicalFunction { private static FunctionResolver rand() { return FunctionDSL.define(BuiltinFunctionName.RAND.getName(), FunctionDSL.impl(() -> new ExprFloatValue(new Random().nextFloat()), FLOAT), FunctionDSL.impl( FunctionDSL.nullMissingHandling( v -> new ExprFloatValue(new Random(v.integerValue()).nextFloat())), FLOAT, INTEGER) ); }  static void register(BuiltinFunctionRepository repository);  }
@Test public void rand_no_arg() { FunctionExpression rand = dsl.rand(); assertEquals(FLOAT, rand.type()); assertTrue( getFloatValue(rand.valueOf(valueEnv())) >= 0 && getFloatValue(rand.valueOf(valueEnv())) < 1); assertEquals("rand()", rand.toString()); }
@Test public void rand_null_value() { FunctionExpression rand = dsl.rand(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(FLOAT, rand.type()); assertTrue(rand.valueOf(valueEnv()).isNull()); }