This repository has been archived on 2023-09-13. You can view files and clone it, but cannot push or open issues or pull requests.
station_obscurum_unity/Assets/FishNet/Runtime/Utility/Extension/Collection.cs

33 lines
843 B
C#

using System;
using System.Collections.Generic;
namespace FishNet.Utility.Extension
{
public static class CollectionFN
{
/// <summary>
/// Random for shuffling.
/// </summary>
private static Random _random = new Random();
/// <summary>
/// Shuffle based on Fisher-Yates shuffle.
/// https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
/// https://stackoverflow.com/questions/273313/randomize-a-listt
/// </summary>
public static void Shuffle<T>(this IList<T> lst)
{
int n = lst.Count;
while (n > 1)
{
n--;
int k = _random.Next(n + 1);
T value = lst[k];
lst[k] = lst[n];
lst[n] = value;
}
}
}
}