RFR 8023155: Ensure functional consistency across Random, ThreadLocalRandom, SplittableRandom

Mike Duigou mike.duigou at oracle.com
Mon Aug 19 19:17:47 UTC 2013

- documentation of "bound" should mention that it is exclusive rather than relying on the return documentation.

- I find disallowing the zero bounds and empty ranges slightly annoying. It requires me to externally special case for situations such as:

Random ran = new Random();
String[] users = {"Fred"}; 

someUser = users[mine.nextInt(users.length - 1)];

This is a frequently used idiom. Yes, forcing the random number generator to return zero is silly but for symmetry it is convenient. An empty range isn't an obvious error (though the "String[] users = {};" case is obviously an error).

On Aug 19 2013, at 04:07 , Paul Sandoz wrote:

> Hi,
> This patch updates Random and ThreadLocalRandom to have functional consistency (for the most part) across Random, ThreadLocalRandom and SplittableRandom:
>  http://cr.openjdk.java.net/~psandoz/tl/JDK-8023155-Random-TLR-SR-sync/webrev/
>  http://cr.openjdk.java.net/~psandoz/tl/JDK-8023155-Random-TLR-SR-sync/specdiff/overview-summary.html
> I have yet to define a common interface e.g. RandomGenerator that Random, ThreadLocalRandom and SplittableRandom could implement, but it would be very easy to do so. Any thoughts on doing this?

Seems worthwhile. 


More information about the core-libs-dev mailing list