Class SeedUtils
- java.lang.Object
-
- org.apache.commons.rng.simple.internal.SeedUtils
-
final class SeedUtils extends java.lang.ObjectUtility for creating seeds.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classSeedUtils.UnsignedByteProviderProvider of unsigned 8-bit integers.
-
Field Summary
Fields Modifier and Type Field Description private static byte[]HEX_DIGIT_ARRAYThe 16 hex digits in an array.private static intMOD_09The modulus256 % 9.private static intMOD_10The modulus256 % 10.private static intMOD_11The modulus256 % 11.private static intMOD_12The modulus256 % 12.private static intMOD_13The modulus256 % 13.private static intMOD_14The modulus256 % 14.private static intMOD_15The modulus256 % 15.
-
Constructor Summary
Constructors Modifier Constructor Description privateSeedUtils()Class contains only static methods.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static intcopyToOutput(byte[] digits, int bits, int upper, int lower)Copy the lower hex digit to the output bits.(package private) static intcreateIntHexPermutation(UniformRandomProvider rng)Creates anintcontaining a permutation of 8 hex digits chosen from 16.(package private) static longcreateLongHexPermutation(UniformRandomProvider rng)Creates alongcontaining a permutation of 8 hex digits chosen from 16 in the upper and lower 32-bits.private static intcreateUpperBitsHexPermutation(SeedUtils.UnsignedByteProvider provider)Creates aintcontaining a permutation of 8 hex digits chosen from 16.private static intnextUnsignedByteInRange(SeedUtils.UnsignedByteProvider provider, int threshold, int n)Get the next unsigned byte in the range[0,n)rejecting any over-represented sample value using the pre-computed modulus.
-
-
-
Field Detail
-
MOD_09
private static final int MOD_09
The modulus256 % 9.- See Also:
- Constant Field Values
-
MOD_10
private static final int MOD_10
The modulus256 % 10.- See Also:
- Constant Field Values
-
MOD_11
private static final int MOD_11
The modulus256 % 11.- See Also:
- Constant Field Values
-
MOD_12
private static final int MOD_12
The modulus256 % 12.- See Also:
- Constant Field Values
-
MOD_13
private static final int MOD_13
The modulus256 % 13.- See Also:
- Constant Field Values
-
MOD_14
private static final int MOD_14
The modulus256 % 14.- See Also:
- Constant Field Values
-
MOD_15
private static final int MOD_15
The modulus256 % 15.- See Also:
- Constant Field Values
-
HEX_DIGIT_ARRAY
private static final byte[] HEX_DIGIT_ARRAY
The 16 hex digits in an array.
-
-
Method Detail
-
createIntHexPermutation
static int createIntHexPermutation(UniformRandomProvider rng)
Creates anintcontaining a permutation of 8 hex digits chosen from 16.- Parameters:
rng- Source of randomness.- Returns:
- hex digit permutation.
-
createLongHexPermutation
static long createLongHexPermutation(UniformRandomProvider rng)
Creates alongcontaining a permutation of 8 hex digits chosen from 16 in the upper and lower 32-bits.- Parameters:
rng- Source of randomness.- Returns:
- hex digit permutation.
-
createUpperBitsHexPermutation
private static int createUpperBitsHexPermutation(SeedUtils.UnsignedByteProvider provider)
Creates aintcontaining a permutation of 8 hex digits chosen from 16.- Parameters:
provider- Source of randomness.- Returns:
- hex digit permutation.
-
nextUnsignedByteInRange
private static int nextUnsignedByteInRange(SeedUtils.UnsignedByteProvider provider, int threshold, int n)
Get the next unsigned byte in the range[0,n)rejecting any over-represented sample value using the pre-computed modulus.This algorithm is as per Lemire (2019) adapted for 8-bit arithmetic.
- Parameters:
provider- Provider of bytes.threshold- Modulus threshold256 % n.n- Upper range (exclusive)- Returns:
- Value.
- See Also:
- Lemire (2019): Fast Random Integer Generation in an Interval
-
copyToOutput
private static int copyToOutput(byte[] digits, int bits, int upper, int lower)Copy the lower hex digit to the output bits. Swap the upper hex digit into the lower position. This is equivalent to a swap step of a Fisher-Yates shuffle on an array but the output of the shuffle are written to the bits.- Parameters:
digits- Digits.bits- Bits.upper- Upper index.lower- Lower index.- Returns:
- Updated bits.
-
-