yashmayya commented on code in PR #17208:
URL: https://github.com/apache/pinot/pull/17208#discussion_r2527897660
##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ArithmeticFunctions.java:
##########
@@ -201,6 +204,34 @@ public static double truncate(double a) {
return Math.signum(a) * Math.floor(Math.abs(a));
}
+ @ScalarFunction
+ public static double rand() {
+ return ThreadLocalRandom.current().nextDouble();
+ }
+
+ @ScalarFunction
+ public static double rand(long seed) {
+ return deterministicRand(seed);
+ }
+
+ private static double deterministicRand(long seed) {
+ // The XOR with 0x5DEECE66DL is inspired by java.util.Random's initial LCG
multiplier scramble,
+ // but unlike Random, we use a custom non-linear mix64 routine for
diffusion and reproducible output.
+ // This approach is chosen to provide deterministic, well-diffused
pseudo-random values, not to match Random's
Review Comment:
Are we not using the actual `Random` class here for the seeded random to
reduce overhead and contention?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]