Esempio n. 1
0
        /// <summary>
        /// Creates a random <see langword="float"/> value within the specified range using the specified
        /// distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random <see langword="float"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximum"/> is less than <paramref name="minimum"/>.</exception>
        public static float AnySingle(this IAnonymousData anon, float minimum, float maximum, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, float.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            return((float)anon.AnyDouble(minimum, maximum, distribution));
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a random <see langword="decimal"/> value using a uniform distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random <see langword="decimal"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        public static decimal AnyDecimal(this IAnonymousData anon, decimal minimum, decimal maximum, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, decimal.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            return((decimal)anon.AnyDouble((double)minimum, (double)maximum, distribution));
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a random <see langword="double"/> value within the specified range using a uniform
        /// distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <returns>A random <see langword="double"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximum"/> is less than <paramref name="minimum"/>.</exception>
        public static double AnyDouble(this IAnonymousData anon, double minimum, double maximum)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, double.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            return(anon.AnyDouble(minimum, maximum, Distribution.Uniform));
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a random <see langword="long"/> value within the specified range using the specified
        /// distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random <see langword="long"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximum"/> is less than <paramref name="minimum"/>.</exception>
        public static long AnyInt64(this IAnonymousData anon, long minimum, long maximum, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, long.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            var min = Math.Max(minimum, long.MinValue + 1);

            return(min + (long)(anon.AnyDouble(0, 1, distribution) * ((double)maximum - (double)min)));
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a random positive <see langword="double"/> value.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <returns>A random positive <see langword="double"/> value.</returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="anon"/> is <see langword="null"/>.</exception>
        /// <remarks>
        /// This method may return a zero value, which strictly makes this "any non-negative" from a mathematical
        /// perspective, but the term "positive" is used because this is what many would expect.
        /// </remarks>
        public static double AnyPositiveDouble(this IAnonymousData anon)
        {
            Argument.NotNull(anon, nameof(anon));

            return(anon.AnyDouble(0, float.MaxValue, Distribution.Uniform));
        }
Esempio n. 6
0
        /// <summary>
        /// Creates a random positive <see langword="double"/> value.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random positive <see langword="double"/> value.</returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="anon"/> is <see langword="null"/>.</exception>
        public static double AnyNegativeDouble(this IAnonymousData anon, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));

            return(anon.AnyDouble(float.MinValue, 0, distribution));
        }
Esempio n. 7
0
        /// <summary>
        /// Creates an anonymous <see cref="bool"/> value using the specified distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random <see cref="bool"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <see langword="null"/>.</exception>
        public static bool AnyBool(this IAnonymousData anon, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));

            return(anon.AnyDouble(0, 1, distribution) >= 0.5);
        }