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

Marcono1234 duke at openjdk.java.net
Sat Mar 5 21:33:01 UTC 2022


On Sat, 5 Mar 2022 19:48:47 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:
> 
>   Fix wrong whitespace

Would it make sense to override `next(int)` to always throw an exception? Even though it should not be possible for a user to call the method on the wrapper, it might be better to be on the safe side; for example in case a new `Random` method which depends on `next(int)` is added in the future (even though this is unlikely).

src/java.base/share/classes/java/util/Random.java line 306:

> 304: 
> 305:     /**
> 306:      * Returns an instance of {@code Random} that delegates method calls to the{@link RandomGenerator}

Suggestion:

     * Returns an instance of {@code Random} that delegates method calls to the {@link RandomGenerator}

(please apply this change manually and don't click the 'commit' button, to not include me as author in this PR)

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

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


More information about the core-libs-dev mailing list