Copilot commented on code in PR #17208:
URL: https://github.com/apache/pinot/pull/17208#discussion_r2525736675


##########
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 actually 
provides the randomness here.
+    // Reference: 
https://docs.oracle.com/javase/8/docs/api/java/util/Random.html
+    long mixed = mix64(seed ^ 0x5DEECE66DL);
+    return (mixed >>> 11) * DOUBLE_UNIT;
+  }

Review Comment:
   The comment mentions 'the randomness here' which is misleading since this is 
a deterministic function. Consider rephrasing to 'provides good distribution 
properties' or 'provides bit mixing' to avoid confusion.



-- 
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]

Reply via email to