CShock/CShocker/Ranges/RandomIntegerRange.cs

21 lines
773 B
C#
Raw Normal View History

2024-01-17 04:11:30 +01:00
namespace CShocker.Ranges;
public abstract class RandomIntegerRange
{
2024-01-17 20:57:53 +01:00
public Range Range { get; init; }
2024-01-17 04:11:30 +01:00
internal RandomIntegerRange(Range range, Range limits)
{
if (range.Max - range.Min < 0)
throw new ArgumentException("Min has to be less or equal Max");
if (range.Min < limits.Min || range.Min > limits.Max)
throw new ArgumentOutOfRangeException(nameof(limits.Min), "Min has to be withing Range 0-100");
if (range.Max < limits.Min || range.Max > limits.Max)
throw new ArgumentOutOfRangeException(nameof(range.Max), "Max has to be withing Range 0-100");
2024-01-17 20:57:53 +01:00
this.Range = range;
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 20:57:53 +01:00
return Random.Shared.Next(Range.Min, Range.Max);
2024-01-17 04:11:30 +01:00
}
}