mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-23 00:38:47 +00:00
(#33) Add NextDouble overload with implied lbound
Behaves similar to Random.Next(int) where lower bound defaults to 0
This commit is contained in:
parent
e05873f383
commit
013e633fce
18
X10D/src/ExceptionMessages.Designer.cs
generated
18
X10D/src/ExceptionMessages.Designer.cs
generated
@ -87,6 +87,24 @@ namespace X10D {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to maxValue must be greater than or equal to 0.
|
||||||
|
/// </summary>
|
||||||
|
internal static string MaxValueGreaterThanEqualTo0 {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("MaxValueGreaterThanEqualTo0", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to maxValue must be greater than or equal to minValue.
|
||||||
|
/// </summary>
|
||||||
|
internal static string MaxValueGreaterThanEqualToMinValue {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("MaxValueGreaterThanEqualToMinValue", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to The stream does not support reading..
|
/// Looks up a localized string similar to The stream does not support reading..
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -47,6 +47,9 @@
|
|||||||
<data name="StreamDoesNotSupportWriting" xml:space="preserve">
|
<data name="StreamDoesNotSupportWriting" xml:space="preserve">
|
||||||
<value>The stream does not support writing.</value>
|
<value>The stream does not support writing.</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="MaxValueGreaterThanEqualTo0" xml:space="preserve">
|
||||||
|
<value>maxValue must be greater than or equal to 0</value>
|
||||||
|
</data>
|
||||||
<data name="MaxValueGreaterThanEqualToMinValue" xml:space="preserve">
|
<data name="MaxValueGreaterThanEqualToMinValue" xml:space="preserve">
|
||||||
<value>maxValue must be greater than or equal to minValue</value>
|
<value>maxValue must be greater than or equal to minValue</value>
|
||||||
</data>
|
</data>
|
||||||
|
@ -54,7 +54,38 @@ namespace X10D.RandomExtensions
|
|||||||
|
|
||||||
return random.NextDouble() >= 0.5;
|
return random.NextDouble() >= 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a non-negative random double-precision floating point number that is less than the specified maximum.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="random">The <see cref="System.Random" /> instance.</param>
|
||||||
|
/// <param name="maxValue">
|
||||||
|
/// The exclusive upper bound of the random number returned. This value must be greater than or equal to
|
||||||
|
/// <paramref name="minValue" />.
|
||||||
|
/// </param>
|
||||||
|
/// <returns>
|
||||||
|
/// A random double-precision floating point number that is greater than or equal to 0, and less than
|
||||||
|
/// <paramref name="maxValue" />.
|
||||||
|
/// </returns>
|
||||||
|
/// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception>
|
||||||
|
/// <exception cref="ArgumentException">
|
||||||
|
/// <paramref name="maxValue" /> is less than <paramref name="minValue" />.
|
||||||
|
/// </exception>
|
||||||
|
public static double NextDouble(this Random random, double maxValue)
|
||||||
|
{
|
||||||
|
if (random is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(random));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxValue < 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentOutOfRangeException(ExceptionMessages.MaxValueGreaterThanEqualTo0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return random.NextDouble(0, maxValue);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a random double-precision floating point number that is within a specified range.
|
/// Returns a random double-precision floating point number that is within a specified range.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user