> For the complete documentation index, see [llms.txt](https://pahutyakv.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pahutyakv.gitbook.io/docs/randomly/min-max.md).

# Min Max

`MinMaxInt` and `MinMaxFloat` are Unity-friendly, serializable structs (`[Serializable]`) designed to easily define and configure numeric ranges (integer or float) directly inside the Unity Inspector. They ensure safety by automatically correcting reversed bounds (`min > max`) and provide handy utility methods for random generation, clamping, and checking values.

***

### <mark style="color:$success;">Types</mark>

* `MinMaxInt` – Represents an inclusive integer range with `Min` and `Max` boundaries.
* `MinMaxFloat` – Represents an inclusive floating-point range with `Min` and `Max` boundaries.

***

### <mark style="color:$success;">Methods</mark>

* `Random()` – Returns a random value uniformly distributed within the inclusive range.
* `Clamp(value)` – Clamps the given value so it stays within the range bounds.
* `Contains(value)` – Returns `true` if the value falls within or equals the range limits.
* `Set(min, max)` – Updates the range boundaries (automatically re-orders them if `min` is greater than `max`).

***

{% code title="Example.cs" %}

```csharp
[SerializeField] private MinMaxInt healthRange = new MinMaxInt(50, 100);
[SerializeField] private MinMaxFloat speedRange = new MinMaxFloat(2.5f, 5.0f);

private void Start()
{
    // Get a random value within the defined range
    int randomHealth = healthRange.Random();
    float randomSpeed = speedRange.Random();

    // Use utility methods
    int clampedHealth = healthRange.Clamp(120); // Returns 100
    bool isInRange = speedRange.Contains(3.0f);   // Returns true

    // Update range programmatically
    healthRange.Set(10, 20);
}
```

{% endcode %}
