Пример #1
0
        private static uint Adjust(IUniformRandomBitGenerator generator, uint upperBoundary)
        {
            if (generator == null)
            {
                throw new ArgumentNullException(nameof(generator));
            }
            if (upperBoundary == 0)
            {
                return(0);
            }
            if (upperBoundary == uint.MaxValue)
            {
                return(generator.Next32Bits());
            }

            ++upperBoundary;
            var   numBuckets = ulong.MaxValue / upperBoundary;
            var   limit      = numBuckets * upperBoundary;
            ulong sample;

            do
            {
                sample = generator.Next64Bits();
            }while (sample >= limit);
            return((uint)(sample / numBuckets));
        }
Пример #2
0
        public static double Next(IUniformRandomBitGenerator generator)
        {
            var entropy = mMask | (generator.Next64Bits() >> 12);

            return(BitConverter.Int64BitsToDouble((long)entropy) - 1.0);
        }