Record Class SeededRandomUtils

java.lang.Object
java.lang.Record
io.bloviate.util.SeededRandomUtils
Record Components:
random - the seeded random source backing all helpers

public record SeededRandomUtils(RandomGenerator random) extends Record
Seeded numeric and string helpers built directly on a RandomGenerator.

The numeric range helpers are adapted from org.apache.commons.lang3.RandomUtils. The string helpers are reimplemented here (rather than delegating to org.apache.commons.lang3.RandomStringUtils) because that class accepts only a Random, whereas the engine now drives generation from a RandomGenerator ("L64X128MixRandom"). For the alphabetic/numeric cases the implementation draws directly from a fixed character pool — the same set of characters RandomStringUtils would yield for those flags — which avoids the draw-and-reject loop entirely. The general [start, end) code-point path is retained for completeness and mirrors the classic RandomStringUtils.random(...) rejection algorithm.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an instance of a SeededRandomUtils record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    double
    nextDouble(double startInclusive, double endExclusive)
    Returns a random double within the range [startInclusive, endExclusive).
    float
    nextFloat(float startInclusive, float endExclusive)
    Returns a random float within the range [startInclusive, endExclusive).
    int
    nextInt(int startInclusive, int endExclusive)
    Returns a random int within the range [startInclusive, endExclusive).
    long
    nextLong(long startInclusive, long endExclusive)
    Returns a random long within the range [startInclusive, endExclusive).
    Returns the value of the random record component.
    random(int count, boolean letters, boolean numbers)
    Generates a random string of the requested length drawn from a fixed character pool selected by the letters/numbers flags: letters only (A-Za-z), digits only (0-9), or alphanumeric (A-Za-z0-9).
    random(int count, int start, int end, boolean letters, boolean numbers)
    Generates a random string of the requested length, drawing code points from the [start, end) range and keeping only letters and/or digits as requested.
    randomAlphabetic(int count)
    Generates a random string of the given length composed only of ASCII letters (A-Za-z).
    randomNumeric(int count)
    Generates a random string of the given length composed only of ASCII digits (0-9).
    randomNumeric(int minLengthInclusive, int maxLengthExclusive)
    Generates a random string of ASCII digits (0-9) whose length is chosen randomly from the range [minLengthInclusive, maxLengthExclusive).
    final String
    Returns a string representation of this record class.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • SeededRandomUtils

      public SeededRandomUtils(RandomGenerator random)
      Creates an instance of a SeededRandomUtils record class.
      Parameters:
      random - the value for the random record component
  • Method Details

    • randomNumeric

      public String randomNumeric(int minLengthInclusive, int maxLengthExclusive)
      Generates a random string of ASCII digits (0-9) whose length is chosen randomly from the range [minLengthInclusive, maxLengthExclusive).
      Parameters:
      minLengthInclusive - the inclusive minimum length of the generated string
      maxLengthExclusive - the exclusive maximum length of the generated string
      Returns:
      a random numeric string
    • randomNumeric

      public String randomNumeric(int count)
      Generates a random string of the given length composed only of ASCII digits (0-9).
      Parameters:
      count - the length of the string to create
      Returns:
      a random numeric string of length count
    • random

      public String random(int count, boolean letters, boolean numbers)
      Generates a random string of the requested length drawn from a fixed character pool selected by the letters/numbers flags: letters only (A-Za-z), digits only (0-9), or alphanumeric (A-Za-z0-9). When both flags are false the general [start, end) code-point path is used, drawing from any code point.
      Parameters:
      count - the length of the string to create
      letters - whether ASCII letters are allowed
      numbers - whether ASCII digits are allowed
      Returns:
      the generated random string
      Throws:
      IllegalArgumentException - if count is negative
    • random

      public String random(int count, int start, int end, boolean letters, boolean numbers)
      Generates a random string of the requested length, drawing code points from the [start, end) range and keeping only letters and/or digits as requested. This mirrors the classic RandomStringUtils.random(count, start, end, letters, numbers, null, random) rejection algorithm, sourcing randomness from this record's RandomGenerator. The common alphabetic/numeric requests are served by random(int, boolean, boolean)'s pool fast path instead.
      Parameters:
      count - the length of the string to create
      start - the inclusive lower bound of code points to draw from (0 selects a default)
      end - the exclusive upper bound of code points to draw from (0 selects a default)
      letters - whether letters are allowed
      numbers - whether digits are allowed
      Returns:
      the generated random string
    • randomAlphabetic

      public String randomAlphabetic(int count)
      Generates a random string of the given length composed only of ASCII letters (A-Za-z).
      Parameters:
      count - the length of the string to create
      Returns:
      a random alphabetic string of length count
    • nextInt

      public int nextInt(int startInclusive, int endExclusive)
      Returns a random int within the range [startInclusive, endExclusive). When the two bounds are equal, that value is returned.
      Parameters:
      startInclusive - the inclusive lower bound (must be non-negative)
      endExclusive - the exclusive upper bound (must be >= startInclusive)
      Returns:
      a random int in the range
      Throws:
      IllegalArgumentException - if endExclusive < startInclusive or startInclusive is negative
    • nextDouble

      public double nextDouble(double startInclusive, double endExclusive)
      Returns a random double within the range [startInclusive, endExclusive). When the two bounds are equal, that value is returned.
      Parameters:
      startInclusive - the inclusive lower bound (must be non-negative)
      endExclusive - the exclusive upper bound (must be >= startInclusive)
      Returns:
      a random double in the range
      Throws:
      IllegalArgumentException - if endExclusive < startInclusive or startInclusive is negative
    • nextFloat

      public float nextFloat(float startInclusive, float endExclusive)
      Returns a random float within the range [startInclusive, endExclusive). When the two bounds are equal, that value is returned.
      Parameters:
      startInclusive - the inclusive lower bound (must be non-negative)
      endExclusive - the exclusive upper bound (must be >= startInclusive)
      Returns:
      a random float in the range
      Throws:
      IllegalArgumentException - if endExclusive < startInclusive or startInclusive is negative
    • nextLong

      public long nextLong(long startInclusive, long endExclusive)
      Returns a random long within the range [startInclusive, endExclusive). When the two bounds are equal, that value is returned. The value is generated directly as a long so the top of wide ranges (above 2^53) remains reachable.
      Parameters:
      startInclusive - the inclusive lower bound (must be non-negative)
      endExclusive - the exclusive upper bound (must be >= startInclusive)
      Returns:
      a random long in the range
      Throws:
      IllegalArgumentException - if endExclusive < startInclusive or startInclusive is negative
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • random

      public RandomGenerator random()
      Returns the value of the random record component.
      Returns:
      the value of the random record component