Class SeedUtils

java.lang.Object
org.apache.commons.rng.simple.internal.SeedUtils

final class SeedUtils extends Object
Utility for creating seeds.
  • Field Details

    • MOD_09

      private static final int MOD_09
      The modulus 256 % 9.
      See Also:
    • MOD_10

      private static final int MOD_10
      The modulus 256 % 10.
      See Also:
    • MOD_11

      private static final int MOD_11
      The modulus 256 % 11.
      See Also:
    • MOD_12

      private static final int MOD_12
      The modulus 256 % 12.
      See Also:
    • MOD_13

      private static final int MOD_13
      The modulus 256 % 13.
      See Also:
    • MOD_14

      private static final int MOD_14
      The modulus 256 % 14.
      See Also:
    • MOD_15

      private static final int MOD_15
      The modulus 256 % 15.
      See Also:
    • HEX_DIGIT_ARRAY

      private static final byte[] HEX_DIGIT_ARRAY
      The 16 hex digits in an array.
  • Constructor Details

    • SeedUtils

      private SeedUtils()
      Class contains only static methods.
  • Method Details

    • createIntHexPermutation

      static int createIntHexPermutation(UniformRandomProvider rng)
      Creates an int containing 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 a long 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

      private static int createUpperBitsHexPermutation(SeedUtils.UnsignedByteProvider provider)
      Creates a int 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 threshold 256 % 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.