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

ExE Boss duke at openjdk.java.net
Mon Feb 28 19:21:32 UTC 2022


On Fri, 25 Feb 2022 23:27:45 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:
> 
>   Update javadoc

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

> 82:         i = 48, j = 0, k = 0,
> 83:         equidistribution = 0
> 84:         )

This should probably not be indented:
Suggestion:

)

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

> 91: 
> 92:     @SuppressWarnings("serial")
> 93:     private static class RandomWrapper extends Random implements RandomGenerator {

This class should also override all the default methods in `RandomGenerator` and forward them to `this.generator`.

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

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


More information about the core-libs-dev mailing list