Record Class SeededRandomUtils
java.lang.Object
java.lang.Record
io.bloviate.util.SeededRandomUtils
- Record Components:
random- the seeded random source backing all helpers
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
ConstructorsConstructorDescriptionSeededRandomUtils(RandomGenerator random) Creates an instance of aSeededRandomUtilsrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.doublenextDouble(double startInclusive, double endExclusive) Returns a randomdoublewithin the range[startInclusive, endExclusive).floatnextFloat(float startInclusive, float endExclusive) Returns a randomfloatwithin the range[startInclusive, endExclusive).intnextInt(int startInclusive, int endExclusive) Returns a randomintwithin the range[startInclusive, endExclusive).longnextLong(long startInclusive, long endExclusive) Returns a randomlongwithin the range[startInclusive, endExclusive).random()Returns the value of therandomrecord component.random(int count, boolean letters, boolean numbers) Generates a random string of the requested length drawn from a fixed character pool selected by theletters/numbersflags: 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 StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
SeededRandomUtils
Creates an instance of aSeededRandomUtilsrecord class.- Parameters:
random- the value for therandomrecord component
-
-
Method Details
-
randomNumeric
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 stringmaxLengthExclusive- the exclusive maximum length of the generated string- Returns:
- a random numeric string
-
randomNumeric
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
Generates a random string of the requested length drawn from a fixed character pool selected by theletters/numbersflags: letters only (A-Za-z), digits only (0-9), or alphanumeric (A-Za-z0-9). When both flags arefalsethe general[start, end)code-point path is used, drawing from any code point.- Parameters:
count- the length of the string to createletters- whether ASCII letters are allowednumbers- whether ASCII digits are allowed- Returns:
- the generated random string
- Throws:
IllegalArgumentException- ifcountis negative
-
random
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 classicRandomStringUtils.random(count, start, end, letters, numbers, null, random)rejection algorithm, sourcing randomness from this record'sRandomGenerator. The common alphabetic/numeric requests are served byrandom(int, boolean, boolean)'s pool fast path instead.- Parameters:
count- the length of the string to createstart- 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 allowednumbers- whether digits are allowed- Returns:
- the generated random string
-
randomAlphabetic
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 randomintwithin 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
intin the range - Throws:
IllegalArgumentException- ifendExclusive < startInclusiveorstartInclusiveis negative
-
nextDouble
public double nextDouble(double startInclusive, double endExclusive) Returns a randomdoublewithin 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
doublein the range - Throws:
IllegalArgumentException- ifendExclusive < startInclusiveorstartInclusiveis negative
-
nextFloat
public float nextFloat(float startInclusive, float endExclusive) Returns a randomfloatwithin 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
floatin the range - Throws:
IllegalArgumentException- ifendExclusive < startInclusiveorstartInclusiveis negative
-
nextLong
public long nextLong(long startInclusive, long endExclusive) Returns a randomlongwithin the range[startInclusive, endExclusive). When the two bounds are equal, that value is returned. The value is generated directly as alongso the top of wide ranges (above2^53) remains reachable.- Parameters:
startInclusive- the inclusive lower bound (must be non-negative)endExclusive- the exclusive upper bound (must be>= startInclusive)- Returns:
- a random
longin the range - Throws:
IllegalArgumentException- ifendExclusive < startInclusiveorstartInclusiveis negative
-
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object). -
random
-