RFR: 8248862: Implement Enhanced Pseudo-Random Number Generators [v3]

Rémi Forax github.com+828220+forax at openjdk.java.net
Wed Nov 25 13:30:05 UTC 2020


On Wed, 25 Nov 2020 13:09:03 GMT, Jim Laskey <jlaskey at openjdk.org> wrote:

>> This PR is to introduce a new random number API for the JDK. The primary API is found in RandomGenerator and RandomGeneratorFactory. Further description can be found in the JEP https://openjdk.java.net/jeps/356 .
>> 
>> javadoc can be found at http://cr.openjdk.java.net/~jlaskey/prng/doc/api/java.base/java/util/random/package-summary.html
>> 
>> old PR:  https://github.com/openjdk/jdk/pull/1273
>
> Jim Laskey has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8248862: Implement Enhanced Pseudo-Random Number Generators
>   
>   Changes to RandomGeneratorFactory requested by @PaulSandoz

src/java.base/share/classes/java/security/SecureRandom.java line 223:

> 221:                 Map.entry(RandomGeneratorProperty.IS_HARDWARE, false)
> 222:         );
> 223:     }

Using Map.of() instead of Map.ofEntries() should simplify the code

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

> 127:                 Map.entry(RandomGeneratorProperty.IS_HARDWARE, false)
> 128:         );
> 129:     }

Using Map.of() should simplify the code

src/java.base/share/classes/java/util/SplittableRandom.java line 181:

> 179:                 Map.entry(RandomGeneratorProperty.IS_HARDWARE, false)
> 180:         );
> 181:     }

Using Map.of() should simplify the code

src/java.base/share/classes/java/util/concurrent/ThreadLocalRandom.java line 169:

> 167:                 Map.entry(RandomGeneratorProperty.IS_STOCHASTIC, false),
> 168:                 Map.entry(RandomGeneratorProperty.IS_HARDWARE, false)
> 169:         );

Using Map.of() should simplify the code

src/java.base/share/classes/java/util/concurrent/ThreadLocalRandom.java line 433:

> 431:     private static final class ThreadLocalRandomProxy extends Random {
> 432:         @java.io.Serial
> 433:         static final long serialVersionUID = 0L;

should be private

src/java.base/share/classes/java/util/concurrent/ThreadLocalRandom.java line 444:

> 442:     }
> 443: 
> 444:     private static final AbstractSpliteratorGenerator proxy = new ThreadLocalRandomProxy();

should be declared inside ThreadLocalRandomProxy, so the value is only initialized when proxy() is called

src/java.base/share/classes/java/util/concurrent/ThreadLocalRandom.java line 453:

> 451:      * @return a {@code RandomGenerator} object that uses {@code ThreadLocalRandom}
> 452:      */
> 453:     public static RandomGenerator proxy() {

proxy is a generic name, is there a better name here ?

src/java.base/share/classes/java/util/concurrent/ThreadLocalRandom.java line 459:

> 457:     // Methods required by class AbstractSpliteratorGenerator
> 458:     public Spliterator.OfInt makeIntsSpliterator(long index, long fence, int origin, int bound) {
> 459:         return new RandomIntsSpliterator(proxy, index, fence, origin, bound);

should use proxy()

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

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



More information about the security-dev mailing list