using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; public static class Module { /// /// 将 List 随机打乱。 /// public static List Shuffle(this List list, System.Random random = null) { random ??= new System.Random(); for (int i = 0; i < list.Count; i++) { int randomIndex = random.Next(list.Count); (list[randomIndex], list[i]) = (list[i], list[randomIndex]); } return list; } /// /// 随机返回数组中的一个元素。 /// public static T RandomOne(this List list, System.Random random = null) { random ??= new System.Random(); return list[random.Next(list.Count)]; } /// /// 可自我返回的 Sort 扩展方法。 /// public static List SortAndReturn(this List list) { list.Sort(); return list; } }