Class RandomGeneratorExamples

java.lang.Object
net.jrodolfo.java_evolution.java17.RandomGeneratorExamples

public class RandomGeneratorExamples extends Object
Demonstrates the enhanced pseudo-random number generator API introduced in Java 17.

Before Java 17, random-number APIs were less unified and algorithm selection was not as discoverable through one common abstraction.

Java 17 added the RandomGenerator interface and RandomGeneratorFactory for selecting named algorithms. This gives code a standard way to choose and discover pseudo-random number generators.

  • Constructor Details

    • RandomGeneratorExamples

      public RandomGeneratorExamples()
  • Method Details

    • boundedRandomValue

      public int boundedRandomValue(String algorithm, int bound)
      Creates a generator by algorithm name and produces a bounded value.
      Parameters:
      algorithm - the random generator algorithm name
      bound - exclusive upper bound
      Returns:
      a generated value between zero inclusive and bound exclusive
    • algorithmExists

      public boolean algorithmExists(String algorithm)
      Checks whether a named random generator algorithm exists.
      Parameters:
      algorithm - the algorithm name
      Returns:
      whether the algorithm is available in this JDK