zoukankan      html  css  js  c++  java
  • 随机泛型

    public static List<T> GetRandomList<T>(List<T> inputList)
    {
        //Copy to a array T[] copyArray = new T[inputList.Count];
        inputList.CopyTo(copyArray);

        //Add range
       
    List<T> copyList = new List<T>();
        copyList.AddRange(copyArray);

        //Set outputList and random
       
    List<T> outputList = new List<T>();
        Random rd = new Random(DateTime.Now.Millisecond);

        while (copyList.Count > 0)
        {
            //Select an index and item
           
    int rdIndex = rd.Next(0, copyList.Count - 1);
            T remove = copyList[rdIndex];

            //remove it from copyList and add it to output
           
    copyList.Remove(remove);
            outputList.Add(remove);
        }
        return outputList;
    }

  • 相关阅读:
    131.著作权
    130.专利权
    idea新用法
    map的put和putIfAbsent使用
    netty的option和childOption
    Java8 lam。。。表达式
    protobuf学习
    protobuf生成
    idea调试
    spring,mapper的参数
  • 原文地址:https://www.cnblogs.com/qq4004229/p/3046456.html
Copyright © 2011-2022 走看看