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

Paul Sandoz paul.sandoz at oracle.com
Mon Aug 19 12:40:49 UTC 2013


On Aug 19, 2013, at 2:26 PM, Peter Levart <peter.levart at gmail.com> wrote:
>> 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?
> 
> Hi Paul,
> 
> Yes, a common interface is something that I missed sometimes. But now that we have lambdas and method references, it's not difficult to just adapt someRandom::nextLong to a LongSupplier or someRandom::nextDouble to a DoubleSupplier, so it somehow looses the importance. Anyway, a special interface might be a better fit for APIs taking random generators as parameters from self-documenting perspective. The consumer of such interface can also have more methods to choose from - it's not just a functional interface. So I'm for such interface.
> 

Yes.

Perhaps it would also allow us to deprecate Random in a future JDK?

Perhaps there could be factory methods to obtain a PRNG based on generator properties rather than picking a specific class. Although there probably needs to two i/faces for that e.g. RandomGenerator and SplittableRandomGenerator (that extends for the former).

Paul.




More information about the core-libs-dev mailing list