RFR: 8294693: Add Collections.shuffle overload that accepts RandomGenerator interface [v3]

Brian Burkhalter bpb at openjdk.org
Sat Oct 29 00:54:25 UTC 2022


On Wed, 12 Oct 2022 13:26:29 GMT, Tagir F. Valeev <tvaleev at openjdk.org> wrote:

>> Java 17 added RandomGenerator interface. However, existing method Collections.shuffle accepts old java.util.Random class. While since Java 19, it's possible to use Random.from(RandomGenerator) wrapper, it would be more convenient to provide direct overload shuffle(List<?> list, RandomGenerator rnd).
>
> Tagir F. Valeev has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Fixes according to review
>   
>   1. Reduce duplication in tests
>   2. Use JumpableGenerator#copy() instead of create(1) in tests, as according to the spec, seed can be ignored
>   3. Simplify documentation for shuffle(List, Random) to avoid duplication.

`jdk.test.lib.RandomFactory` can be used to generate a reproducible sequence of random numbers. An example of its use may be seen for example in `java/nio/file/Files/CopyAndMove.java`

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

PR: https://git.openjdk.org/jdk/pull/10520


More information about the core-libs-dev mailing list