Class SeedUtils
java.lang.Object
org.apache.commons.rng.simple.internal.SeedUtils
Utility for creating seeds.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Provider of unsigned 8-bit integers. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final byte[]
The 16 hex digits in an array.private static final int
The modulus256 % 9
.private static final int
The modulus256 % 10
.private static final int
The modulus256 % 11
.private static final int
The modulus256 % 12
.private static final int
The modulus256 % 13
.private static final int
The modulus256 % 14
.private static final int
The modulus256 % 15
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static int
copyToOutput
(byte[] digits, int bits, int upper, int lower) Copy the lower hex digit to the output bits.(package private) static int
Creates anint
containing a permutation of 8 hex digits chosen from 16.(package private) static long
Creates along
containing a permutation of 8 hex digits chosen from 16 in the upper and lower 32-bits.private static int
Creates aint
containing a permutation of 8 hex digits chosen from 16.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.
-
Field Details
-
MOD_09
private static final int MOD_09The modulus256 % 9
.- See Also:
-
MOD_10
private static final int MOD_10The modulus256 % 10
.- See Also:
-
MOD_11
private static final int MOD_11The modulus256 % 11
.- See Also:
-
MOD_12
private static final int MOD_12The modulus256 % 12
.- See Also:
-
MOD_13
private static final int MOD_13The modulus256 % 13
.- See Also:
-
MOD_14
private static final int MOD_14The modulus256 % 14
.- See Also:
-
MOD_15
private static final int MOD_15The modulus256 % 15
.- See Also:
-
HEX_DIGIT_ARRAY
private static final byte[] HEX_DIGIT_ARRAYThe 16 hex digits in an array.
-
-
Constructor Details
-
SeedUtils
private SeedUtils()Class contains only static methods.
-
-
Method Details
-
createIntHexPermutation
Creates anint
containing a permutation of 8 hex digits chosen from 16.- Parameters:
rng
- Source of randomness.- Returns:
- hex digit permutation.
-
createLongHexPermutation
Creates along
containing 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
Creates aint
containing 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:
-
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.
-