Files
BABA_YAGA/Assets/Scripts/GameSetup/Maze/Extensions.cs
2026-04-21 23:28:49 +07:00

26 lines
641 B
C#

using System.Collections.Generic;
namespace Hallucinate.GameSetup.Maze.Extensions
{
public static class ListExtensions
{
private static System.Random _rng = new System.Random();
/// <summary>
/// Shuffles a list using the Fisher-Yates algorithm.
/// </summary>
public static void Shuffle<T>(this IList<T> list)
{
int n = list.Count;
while (n > 1)
{
n--;
int k = _rng.Next(n + 1);
T value = list[k];
list[k] = list[n];
list[n] = value;
}
}
}
}