Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8259270

Add getDefault() methods to RandomGenerator

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Withdrawn
    • Icon: P3 P3
    • None
    • core-libs
    • None
    • source
    • low
    • Low risk of introducing conflicting name.
    • Java API
    • SE

      Summary

      Introduce methods to simplify the selection of basic RandomGenerators.

      Problem

      Without using a specific algorithm, the RandomGenerator API recommends that the user should use a query to select an appropriate an algorithm. The queries could be daunting for a user that just wants a basic RandomGenerator. Ex.,

      RandomGeneratorFactory<RandomGenerator> best = RandomGenerator.all()
          .sorted((f, g) -> Integer.compare(f.stateBits(), g.stateBits()))
          .findFirst()
          .orElseThrow();

      Solution

      Provide methods that return a basic RandomGenerator or RandomGeneratorFactory.

      Specification

          /**
           * Returns a {@link RandomGeneratorFactory} meeting the minimal requirement
           * of having an algorithm whose state bits are greater than or equal 64.
           *
           * @implNote  Since algorithms will improve over time, there is no
           * guarantee that this method will return the same algorithm each time.
           *
           * @return a {@link RandomGeneratorFactory}
           */
          static RandomGeneratorFactory<RandomGenerator> getDefaultFactory() {
              return factoryOf("L32X64MixRandom");
          }
      
          /**
           * Returns a {@link RandomGenerator} meeting the minimal requirement
           * of having an algorithm whose state bits are greater than or equal 64.
           *
           * @implNote  Since algorithms will improve over time, there is no
           * guarantee that this method will return the same algorithm each time.
           *
           * @return a {@link RandomGenerator}
           */
          static RandomGenerator getDefault() {
              return of("L32X64MixRandom");
          }

            jlaskey Jim Laskey
            jlaskey Jim Laskey
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: