NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Framework/Algorithm.cs

25 lines
603 B
C#
Raw Permalink Normal View History

2023-08-22 19:08:45 +08:00
using System.Collections.Generic;
using UnityEngine;
using Random = System.Random;
namespace Framework
{
public class Algorithm
{
public static void ShuffleInPlace<T>(IList<T> list)
{
var random = new Random(Time.frameCount);
for (int i = 0; i < list.Count - 1; i++)
{
int j = random.Next(i, list.Count);
if (i != j)
{
T temp = list[j];
list[j] = list[i];
list[i] = temp;
}
}
}
}
}