Class UniformLongSampler

    • Constructor Detail

      • UniformLongSampler

        UniformLongSampler​(UniformRandomProvider rng)
        Parameters:
        rng - Generator of uniformly distributed random numbers.
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • of

        public static UniformLongSampler of​(UniformRandomProvider rng,
                                            long lower,
                                            long upper)
        Creates a new discrete uniform distribution sampler.
        Parameters:
        rng - Generator of uniformly distributed random numbers.
        lower - Lower bound (inclusive) of the distribution.
        upper - Upper bound (inclusive) of the distribution.
        Returns:
        the sampler
        Throws:
        java.lang.IllegalArgumentException - if lower > upper.
      • createZeroBoundedSampler

        private static UniformLongSampler createZeroBoundedSampler​(UniformRandomProvider rng,
                                                                   long upper)
        Create a new sampler for the range 0 inclusive to upper inclusive.

        This can handle any positive upper.

        Parameters:
        rng - Generator of uniformly distributed random numbers.
        upper - Upper bound (inclusive) of the distribution. Must be positive.
        Returns:
        the sampler
      • isPowerOf2

        private static boolean isPowerOf2​(long value)
        Checks if the value is a power of 2.

        This returns true for the value Long.MIN_VALUE which can be handled as an unsigned long of 2^63.

        Parameters:
        value - Value.
        Returns:
        true if a power of 2