From defa8cb89012e3b2a0e60ce7e285aa8a0f58126c Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sun, 7 Mar 2021 18:28:09 +0000 Subject: [PATCH] (#34) Add Random.NextSingle([float, float]) --- X10D/src/RandomExtensions/RandomExtensions.cs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/X10D/src/RandomExtensions/RandomExtensions.cs b/X10D/src/RandomExtensions/RandomExtensions.cs index c5eb9d4..e989b7d 100644 --- a/X10D/src/RandomExtensions/RandomExtensions.cs +++ b/X10D/src/RandomExtensions/RandomExtensions.cs @@ -131,6 +131,44 @@ namespace X10D.RandomExtensions return list[random.Next(list.Count)]; } + /// + /// Returns a random single-precision floating point number between 0 and 1. + /// + /// The instance. + /// A random single-precision floating point number between 0 and 1. + /// is . + public static float NextSingle(this Random random) + { + if (random is null) + { + throw new ArgumentNullException(nameof(random)); + } + + return random.NextSingle(0, 1); + } + + /// + /// Returns a random single-precision floating point number that is within a specified range. + /// + /// The instance. + /// The inclusive lower bound of the random number returned. + /// + /// The inclusive lower bound of the random number returned. This value must be greater than or equal to + /// . + /// + /// + /// A random single-precision floating point number between and + /// . + /// + /// is . + /// + /// is less than . + /// + public static float NextSingle(this Random random, float minValue, float maxValue) + { + return (float)random.NextDouble(minValue, maxValue); + } + /// /// Returns a new string of a specified length which is composed of specified characters. ///