mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-25 22:18:34 +01:00
Added RandomExtensions.NextSingle with minimum and maximum values
This commit is contained in:
parent
04829f1695
commit
2e8a8244a3
2 changed files with 33 additions and 0 deletions
|
@ -21,6 +21,7 @@ Additions
|
||||||
- Added SingleRandom and SeedSource
|
- Added SingleRandom and SeedSource
|
||||||
- Added TokenizedString.GetArea
|
- Added TokenizedString.GetArea
|
||||||
- Added InputHandler.WasPressedForLess and related methods as well as InputHandler.IsPressedIgnoreRepeats
|
- 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**
|
- **Added the ability to find paths to one of multiple goals using AStar**
|
||||||
|
|
||||||
Improvements
|
Improvements
|
||||||
|
|
|
@ -55,5 +55,37 @@ namespace MLEM.Extensions {
|
||||||
throw new IndexOutOfRangeException();
|
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
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue