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

Roger Riggs rriggs at openjdk.java.net
Fri Jan 28 16:05:12 UTC 2022


On Fri, 28 Jan 2022 00:36:01 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 four additional commits since the last revision:
> 
>  - make sure setseed its initialized and throw
>  - remove tabs
>  - Change name of function from wrapRandom to wrap
>  - Change variable name and wording in javadocs

(For future reference: As tempting as it is to make other small improvements to the code such as missing but optional @ Overrides, it obscures the changes that are the subject of the PR.).

src/java.base/share/classes/jdk/internal/util/random/RandomWrapper.java line 36:

> 34: /**
> 35:  * Class used to wrap a {@link java.util.random.RandomGenerator} to
> 36:  * {@link java.util.Random}

Missing period at end of sentence.

src/java.base/share/classes/jdk/internal/util/random/RandomWrapper.java line 42:

> 40: public class RandomWrapper extends Random implements RandomGenerator {
> 41:     private final RandomGenerator generator;
> 42:     private boolean initialized;

"final" would be appropriate here.

src/java.base/share/classes/jdk/internal/util/random/RandomWrapper.java line 59:

> 57:     /**
> 58:      * setSeed does not exist in {@link java.util.random.RandomGenerator} so can't
> 59:      * use it

Missing period.

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

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


More information about the core-libs-dev mailing list