1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 04:53:29 +01:00

Added RandomExtensions.NextSingle with minimum and maximum values

This commit is contained in:
Ell 2023-01-07 20:01:22 +01:00
parent 04829f1695
commit 2e8a8244a3
2 changed files with 33 additions and 0 deletions

View file

@ -21,6 +21,7 @@ Additions
- Added SingleRandom and SeedSource
- Added TokenizedString.GetArea
- Added InputHandler.WasPressedForLess and related methods as well as InputHandler.IsPressedIgnoreRepeats
- Added RandomExtensions.NextSingle with minimum and maximum values
- **Added the ability to find paths to one of multiple goals using AStar**
Improvements

View file

@ -55,5 +55,37 @@ namespace MLEM.Extensions {
throw new IndexOutOfRangeException();
}
/// <summary>
/// Returns a random floating-point number that is greater than or equal to 0, and less than <paramref name="maxValue"/>.
/// </summary>
/// <param name="random">The random.</param>
/// <param name="maxValue">The (exclusive) maximum value.</param>
/// <returns>A single-precision floating point number that is greater than or equal to 0, and less than <paramref name="maxValue"/>.</returns>
public static float NextSingle(this Random random, float maxValue) {
return maxValue * random.NextSingle();
}
/// <summary>
/// Returns a random floating-point number that is greater than or equal to <paramref name="minValue"/>, and less than <paramref name="maxValue"/>.
/// </summary>
/// <param name="random">The random.</param>
/// <param name="minValue">The (inclusive) minimum value.</param>
/// <param name="maxValue">The (exclusive) maximum value.</param>
/// <returns>A single-precision floating point number that is greater than or equal to <paramref name="minValue"/>, and less than <paramref name="maxValue"/>.</returns>
public static float NextSingle(this Random random, float minValue, float maxValue) {
return (maxValue - minValue) * random.NextSingle() + minValue;
}
#if !NET6_0_OR_GREATER
/// <summary>
/// Returns a random floating-point number that is greater than or equal to 0, and less than 1.
/// </summary>
/// <param name="random">The random.</param>
/// <returns>A single-precision floating point number that is greater than or equal to 0, and less than 1.</returns>
public static float NextSingle(this Random random) {
return (float) random.NextDouble();
}
#endif
}
}