Пример #1
0
        /// <inheritdoc />
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="minValue"/> is less than 0.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maxValue"/> is less than 0.</exception>
        /// <exception cref="Exception">A delegate callback throws an exception.</exception>
        public double NextDouble(double minValue, double maxValue)
        {
            Guard.IsGreaterThanOrEqualTo(minValue, 0, nameof(minValue));
            Guard.IsGreaterThanOrEqualTo(maxValue, 0, nameof(maxValue));

            var ordered = new OrderedElements <double>(minValue, maxValue);

            return(NextDouble(ordered.Greater - ordered.Lesser) + ordered.Lesser);
        }
Пример #2
0
        /// <inheritdoc />
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="minValue"/> is less than 0.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maxValue"/> is less than 0.</exception>
        /// <exception cref="Exception">A delegate callback throws an exception.</exception>
        public long NextInt64(long minValue, long maxValue)
        {
            Guard.IsGreaterThanOrEqualTo(minValue, 0, nameof(minValue));
            Guard.IsGreaterThanOrEqualTo(maxValue, 0, nameof(maxValue));

            var ordered = new OrderedElements <long>(minValue, maxValue);

            return(NextInt64(ordered.Greater - ordered.Lesser) + ordered.Lesser);
        }
Пример #3
0
        /// <inheritdoc />
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="minValue"/> is less than 0.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maxValue"/> is less than 0.</exception>
        /// <exception cref="Exception">A delegate callback throws an exception.</exception>
        public int NextInt32(int minValue, int maxValue)
        {
            Guard.IsGreaterThanOrEqualTo(minValue, 0, nameof(minValue));
            Guard.IsGreaterThanOrEqualTo(maxValue, 0, nameof(maxValue));

            var ordered = new OrderedElements <int>(minValue, maxValue);

            return(NextInt32(ordered.Greater - ordered.Lesser) + ordered.Lesser);
        }
Пример #4
0
        /// <inheritdoc />
        /// <exception cref="Exception">A delegate callback throws an exception.</exception>
        public int NextInt32(int minValue, int maxValue)
        {
            var ordered = new OrderedElements <int>(minValue, maxValue);

            // System.Random is exclusive upper.
            int maxActual = ordered.Greater == int.MaxValue ? int.MaxValue : ordered.Greater + 1;

            return(Random.Next(ordered.Lesser, maxActual));
        }
Пример #5
0
        /// <inheritdoc />
        /// <exception cref="ArgumentException"><paramref name="minValue"/> is less than 0.</exception>
        /// <exception cref="ArgumentException"><paramref name="maxValue"/> is less than 0.</exception>
        /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired. </exception>
        /// <exception cref="Exception">A delegate callback throws an exception.</exception>
        public int NextInt32(int minValue, int maxValue)
        {
            Guard.IsGreaterThanOrEqualTo(minValue, 0, nameof(minValue));
            Guard.IsGreaterThanOrEqualTo(maxValue, 0, nameof(maxValue));

            var ordered = new OrderedElements <int>(minValue, maxValue);

            int result;

            do
            {
                result = NextInt32();
            } while (result < ordered.Lesser || result > ordered.Greater);

            return(result);
        }
Пример #6
0
        /// <inheritdoc />
        /// <exception cref="ArgumentException"><paramref name="minValue"/> is less than 0.</exception>
        /// <exception cref="ArgumentException"><paramref name="maxValue"/> is less than 0.</exception>
        /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired. </exception>
        /// <exception cref="Exception">A delegate callback throws an exception.</exception>
        public double NextDouble(double minValue, double maxValue)
        {
            Guard.IsGreaterThanOrEqualTo(minValue, 0, nameof(minValue));
            Guard.IsGreaterThanOrEqualTo(maxValue, 0, nameof(maxValue));

            var ordered = new OrderedElements <double>(minValue, maxValue);

            double result;

            do
            {
                result = NextDouble();
            } while (result < ordered.Lesser || result > ordered.Greater);

            return(result);
        }
Пример #7
0
        /// <inheritdoc />
        /// <exception cref="ArgumentException"><paramref name="minValue"/> is less than 0.</exception>
        /// <exception cref="ArgumentException"><paramref name="maxValue"/> is less than 0.</exception>
        /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired. </exception>
        /// <exception cref="Exception">A delegate callback throws an exception.</exception>
        public long NextInt64(long minValue, long maxValue)
        {
            Guard.IsGreaterThanOrEqualTo(minValue, 0, nameof(minValue));
            Guard.IsGreaterThanOrEqualTo(maxValue, 0, nameof(maxValue));

            var ordered = new OrderedElements <long>(minValue, maxValue);

            long result;

            do
            {
                result = NextInt64();
            } while (result < ordered.Lesser || result > ordered.Greater);

            return(result);
        }