不重复随机
public static List<T> MyRandom<T>(ref List<T> tras, int number) { if (number > tras.Count) { Debug.Log("要取的个数大于数组长度!"); return null; } List<T> result = new List<T>(); List<int> Numid = new List<int>(); for (int i = 0; i < tras.Count; i++) { Numid.Add(i); } int r; while (Numid.Count > tras.Count - number) { r = UnityEngine.Random.Range(0, Numid.Count); result.Add(tras[Numid[r]]); Numid.Remove(Numid[r]); } return (result); }
posted on 2019-02-27 10:55 sevenPixels 阅读(114) 评论(0) 编辑 收藏 举报