using System; using System.Text.Json.Serialization; namespace Artemis.Core; /// /// Represents a range between two single-precision floating point numbers /// public readonly struct FloatRange { 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 FloatRange(float start, float end) { Start = start; End = end; _rand = Random.Shared; } /// /// Gets the start value of the range /// public float Start { get; } /// /// Gets the end value of the range /// public float 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(float 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 float GetRandomValue(bool inclusive = true) { if (inclusive) return _rand.Next((int) (Start * 100), (int) (End * 100)) / 100f; return _rand.Next((int) (Start * 100) + 1, (int) (End * 100)) / 100f; } }