2019-12-04 13:06:53 +01:00
|
|
|
using System;
|
2020-01-04 21:55:10 +01:00
|
|
|
using Microsoft.Xna.Framework;
|
2019-12-04 13:06:53 +01:00
|
|
|
using MonoGame.Extended;
|
|
|
|
|
2024-07-19 20:02:28 +02:00
|
|
|
namespace MLEM.Extended.Maths {
|
2020-05-22 20:32:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// A set of extension methods for dealing with <see cref="Random"/>
|
|
|
|
/// </summary>
|
2019-12-04 13:06:53 +01:00
|
|
|
public static class RandomExtensions {
|
|
|
|
|
2020-05-22 20:32:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Returns a random number in the given range.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="random">The random to use for generation</param>
|
|
|
|
/// <param name="range">The range in which numbers will be generated</param>
|
|
|
|
/// <returns>A number in the given range</returns>
|
2019-12-04 13:06:53 +01:00
|
|
|
public static int Range(this Random random, Range<int> range) {
|
|
|
|
return random.Next(range.Min, range.Max);
|
|
|
|
}
|
|
|
|
|
2020-05-22 20:32:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Returns a random number in the given range.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="random">The random to use for generation</param>
|
|
|
|
/// <param name="range">The range in which numbers will be generated</param>
|
|
|
|
/// <returns>A number in the given range</returns>
|
2019-12-04 13:06:53 +01:00
|
|
|
public static float Range(this Random random, Range<float> range) {
|
|
|
|
return random.NextSingle(range.Min, range.Max);
|
|
|
|
}
|
|
|
|
|
2020-05-22 20:32:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Returns a random vector whose x and y values are in the given range.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="random">The random to use for generation</param>
|
|
|
|
/// <param name="min">The minimum value for each coordinate</param>
|
|
|
|
/// <param name="max">The maximum value for each coordinate</param>
|
|
|
|
/// <returns>A random vector in the given range</returns>
|
2020-01-04 21:57:10 +01:00
|
|
|
public static Vector2 NextVector2(this Random random, float min, float max) {
|
2020-01-04 21:55:10 +01:00
|
|
|
return new Vector2(random.NextSingle(min, max), random.NextSingle(min, max));
|
|
|
|
}
|
|
|
|
|
2019-12-04 13:06:53 +01:00
|
|
|
}
|
2022-06-17 18:23:47 +02:00
|
|
|
}
|