// MIT License - Copyright (c) 2025 wallstop // Full license text: https://github.com/wallstop/unity-helpers/blob/main/LICENSE namespace WallstopStudios.UnityHelpers.Core.Random { using System.Collections.Generic; public sealed class RandomComparer : IComparer { private readonly IRandom _random; private readonly Dictionary _cachedValues; public RandomComparer(IRandom random) { _random = random; _cachedValues = new Dictionary(); } public int Compare(T x, T y) { if (!_cachedValues.TryGetValue(x, out int xValue)) { xValue = _random.Next(); _cachedValues[x] = xValue; } if (!_cachedValues.TryGetValue(y, out int yValue)) { yValue = _random.Next(); _cachedValues[y] = yValue; } return xValue.CompareTo(yValue); } } }