diff --git a/X10D/src/RandomExtensions/RandomExtensions.cs b/X10D/src/RandomExtensions/RandomExtensions.cs index 3ff23ed..1271c01 100644 --- a/X10D/src/RandomExtensions/RandomExtensions.cs +++ b/X10D/src/RandomExtensions/RandomExtensions.cs @@ -157,19 +157,31 @@ public static class RandomExtensions } /// - /// Returns a random single-precision floating point number between 0 and 1. + /// Returns a non-negative random single-precision floating point number that is less than the specified maximum. /// /// The instance. - /// A random single-precision floating point number between 0 and 1. + /// + /// The exclusive upper bound of the random number returned. This value must be greater than or equal to 0. + /// + /// + /// A random single-precision floating point number that is greater than or equal to 0, and less than + /// . + /// /// is . - public static float NextSingle(this Random random) + /// is less than 0. + public static float NextSingle(this Random random, float maxValue) { if (random is null) { throw new ArgumentNullException(nameof(random)); } - return random.NextSingle(0, 1); + if (maxValue < 0) + { + throw new ArgumentOutOfRangeException(ExceptionMessages.MaxValueGreaterThanEqualTo0); + } + + return random.NextSingle(0, maxValue); } /// @@ -191,7 +203,7 @@ public static class RandomExtensions /// public static float NextSingle(this Random random, float minValue, float maxValue) { - return (float)random.NextDouble(minValue, maxValue); + return MathUtility.Lerp(minValue, maxValue, random.NextSingle()); } ///