Copilot commented on code in PR #17208:
URL: https://github.com/apache/pinot/pull/17208#discussion_r2525739631
##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ArithmeticFunctions.java:
##########
@@ -201,6 +204,30 @@ 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) {
+ // Mirror java.util.Random's initial LCG scramble by xor'ing with the
well-known multiplier before
+ // feeding the value into the non-linear mix64 routine, which provides the
diffusion for reproducible outputs.
+ // Reference:
https://docs.oracle.com/javase/8/docs/api/java/util/Random.html
Review Comment:
The comment references java.util.Random's LCG scramble, but the
implementation uses a custom mix64 algorithm. Consider clarifying that the XOR
with 0x5DEECE66DL is inspired by Random's multiplier but the subsequent mixing
differs from Random's actual algorithm, or explain why this particular approach
was chosen for deterministic output.
```suggestion
// 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 output.
// Reference for multiplier:
https://docs.oracle.com/javase/8/docs/api/java/util/Random.html
```
--
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]