RFR: 8279598: Provide adapter from RandomGenerator to Random [v19]

liach duke at openjdk.java.net
Thu Mar 17 15:47:39 UTC 2022


On Wed, 16 Mar 2022 14:54:41 GMT, Yasser Bazzi <duke at openjdk.java.net> wrote:

>> Hi, could i get a review on this implementation proposed by Stuart Marks, i decided to use the https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/random/RandomGenerator.html interface to create the default method `asRandom()` that wraps around the newer algorithms to be used on classes that do not accept the new interface.
>> 
>> Some things to note as proposed by the bug report, the protected method next(int bits) is not overrided and setSeed() method if left blank up to discussion on what to do with it.
>> 
>> Small test done on https://gist.github.com/YShow/da678561419cda8e32fccf3a27a649d4
>
> Yasser Bazzi has updated the pull request incrementally with one additional commit since the last revision:
> 
>   add since in javadoc

FYI in the CSR review, Joe Darcy points out:

> Okay; I've looked over this CSR in more detail and think some additional supporting changes in java.util.Random should be made to address some existing shortcoming in the spec there.
>
> In particular, I think Random.setSeed's spec should be changed to have a general contract that it is an optional operation, i.e. may throw UnsupportedOperationException as ThreadLocalRandom.setSeed already does. The particulars of Random.setSeed should be moved into an implSpec, which would only apply to that non-overridden method.
>
> (More generally, java.util.Random would likely benefit from a pass to use implNote, implSpec, etc., but I think only setSeed needs to be adjusted for the purposes of this CSR.)
>
> Moving back to Provisional.

So need an update to `Random.setSeed`'s API documentation and update the CSR correspondingly.

-------------

PR: https://git.openjdk.java.net/jdk/pull/7001


More information about the core-libs-dev mailing list