CShock/CShocker/Ranges/RandomIntegerRange.cs

27 lines
876 B
C#
Raw Normal View History

2024-01-17 04:11:30 +01:00
namespace CShocker.Ranges;
public abstract class RandomIntegerRange
{
2024-01-17 22:16:40 +01:00
public short Min, Max;
internal RandomIntegerRange(short min, short max, short minLimit, short maxLimit)
2024-01-17 04:11:30 +01:00
{
2024-01-17 22:16:40 +01:00
if (max - min < 0)
2024-01-17 04:11:30 +01:00
throw new ArgumentException("Min has to be less or equal Max");
2024-01-17 22:16:40 +01:00
if (min < minLimit || min > maxLimit)
throw new ArgumentOutOfRangeException(nameof(min), $"Min has to be withing Range {minLimit}-{maxLimit}");
if (max < minLimit || max > maxLimit)
throw new ArgumentOutOfRangeException(nameof(max), $"Max has to be withing Range {minLimit}-{maxLimit}");
this.Min = min;
this.Max = max;
2024-01-17 04:11:30 +01:00
}
2024-01-17 19:39:48 +01:00
public int GetRandomRangeValue()
2024-01-17 04:11:30 +01:00
{
2024-01-17 22:16:40 +01:00
return Random.Shared.Next(this.Min, this.Max);
2024-01-17 04:11:30 +01:00
}
2024-01-17 23:12:51 +01:00
public override string ToString()
{
return $"Min: {Min} Max: {Max}";
}
2024-01-17 04:11:30 +01:00
}