New candidate JEP: 356: Enhanced Pseudo-Random Number Generators

Kasper Nielsen kasperni at gmail.com
Mon Jun 24 07:46:46 UTC 2019


Hi Guy,

This looks really good, a couple of quick questions and comments.

1)
I think a natural home for this would be java.math?

2)
Couldn't we use default methods and skip all of the abstract classes?
I assume all the abstract classes are stateless. Don't know if there
would be performance penalties though.

3)
Wouldn't people have to implement nextBytes() as well.
An efficient implementation needs to know whether or not the source
is 32 bit or 64 bit (or maybe 128 bit at some point).
Which is difficult if we only have a single base class.
Maybe create Rng32, Rng64 that extends from Rng

4)
Can we add an interface for generating seeds?

public interface SeedGenerator {
  default generateLong() {
    return Long.convert(generateSeed(8));
  }
  byte[] generateSeed(int length);
}

Right now we have a mix of long and byte[]. And if you have
algorithms that need 128 bit seeds and you store all your states
in longs. Having something like this would be really useful.

5)
A clone() or copy() method would also be nice. It is really useful for testing.

6)
Is reseeding going to be part of the API? I've never really liked having to
use Random.setSeed() but understand it can be useful, for example, for
algorithms that are secure.

7)
It would be really if we got a simple utility class that allows sampling from
common non-uniform distributions:

public static IntSupplier poissonSamplingGenerator(Rng r, double mean)
public static IntStream poissonSamplingStream(Rng r, double mean)

Thanks
  Kasper



/Kasper

On Fri, 21 Jun 2019 at 19:37, <mark.reinhold at oracle.com> wrote:
>
> By my count this JEP would add ten new public types to the java.util
> package.  Is it time to consider creating a java.util.random subpackage?
>
> - Mark


More information about the core-libs-dev mailing list