using System;
using System.Text.Json.Serialization;
namespace Artemis.Core;
///
/// Represents a range between two signed integers
///
public readonly struct IntRange
{
private readonly Random _rand;
///
/// Creates a new instance of the class
///
/// The start value of the range
/// The end value of the range
[JsonConstructor]
public IntRange(int start, int end)
{
Start = start;
End = end;
_rand = Random.Shared;
}
///
/// Gets the start value of the range
///
public int Start { get; }
///
/// Gets the end value of the range
///
public int End { get; }
///
/// Determines whether the given value is in this range
///
/// The value to check
///
/// Whether the value may be equal to or
/// Defaults to
///
///
public bool IsInRange(int value, bool inclusive = true)
{
if (inclusive)
return value >= Start && value <= End;
return value > Start && value < End;
}
///
/// Returns a pseudo-random value between and
///
/// Whether the value may be equal to
/// The pseudo-random value
public int GetRandomValue(bool inclusive = true)
{
if (inclusive)
return _rand.Next(Start, End + 1);
return _rand.Next(Start + 1, End);
}
}