Class SeedUtils


  • final class SeedUtils
    extends java.lang.Object
    Utility for creating seeds.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  SeedUtils.UnsignedByteProvider
      Provider of unsigned 8-bit integers.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static byte[] HEX_DIGIT_ARRAY
      The 16 hex digits in an array.
      private static int MOD_09
      The modulus 256 % 9.
      private static int MOD_10
      The modulus 256 % 10.
      private static int MOD_11
      The modulus 256 % 11.
      private static int MOD_12
      The modulus 256 % 12.
      private static int MOD_13
      The modulus 256 % 13.
      private static int MOD_14
      The modulus 256 % 14.
      private static int MOD_15
      The modulus 256 % 15.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private SeedUtils()
      Class contains only static methods.
    • Constructor Detail

      • SeedUtils

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

      • 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:
        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.