mikemccand opened a new issue, #12771:
URL: https://github.com/apache/lucene/issues/12771

   ### Description
   
   Spinoff from backporting #12506 which was using the [Random#nextInt(int, 
int) 
method](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/random/RandomGenerator.html#nextInt(int,int)),
 but that's not available in JDK 11.
   
   While doing this I read its javadocs and this part kinda scared me:
   
   ```
   Implementation Requirements:
   
   The default implementation checks that origin and bound are positive ints. 
Then invokes nextInt(), limiting the result to be greater that or equal origin 
and less than bound. If bound is a power of two then limiting is a simple 
masking operation. Otherwise, the result is re-calculated by invoking nextInt() 
until the result is greater than or equal origin and less than bound.
   ```
   
   Specifically the `Otherwise, the result is re-calculated by invoking 
nextInt() until the result is greater than or equal origin and less than 
bound.`.
   
   I think the impl favors "true-ish" randomness over performance?  But I think 
it means if you ask for a small range it might have to run a great many 
iterations to finally find a random number in bounds.
   
   Maybe we should ban that?  Seems like a performance trap for our tests.  And 
anyways we have other ways to get random ints in a range (`TestUtil.nextInt`, 
randomizedtesting's `RandomNumbers.randomIntBetween`).
   
   ### Version and environment details
   
   _No response_


-- 
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: issues-unsubscr...@lucene.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to