C#数组随机排序

public static T[] RandomSort(T[] array)
        {
            int len = array.Length;

            Random rand = new Random();
            System.Collections.Generic.List list = new System.Collections.Generic.List();
            T[] ret = new T[len];
            int i = 0;
            while (list.Count < len)
            {
                int iter = rand.Next(0, len);
                if (!list.Contains(iter))
                {
                    list.Add(iter);
                    ret[i] = array[iter];
                    i++;
                }
            }
            return ret;
        }

你可能感兴趣的:(C#,c#,random,list)