• Unity中集合的随机数(指定长度—List、Dictionary)


    获取Dictionary中不重复的随机数(返回Dictionary):
            public static Dictionary RandomValues(Dictionary allDic, int randomCount)
            {
                System.Random rand = new System.Random();
                Dictionary newDic = new Dictionary();
                int size = allDic.Count;
                randomCount = randomCount > size ? size : randomCount;
                List values = Enumerable.ToList(allDic.Keys);
                while (newDic.Count < randomCount)
                {
                    TKey tk = values[rand.Next(size)];
                    if (!newDic.Keys.Contains(tk))
                    {
                        newDic[tk] = allDic[tk];
                    }
                }
                return newDic;
            }

    获取List中不重复的随机数(返回List): 

     public static List RandomValues(List allList, int randomCount)
            {
                System.Random rand = new System.Random();
                List newList = new List();
                int size = allList.Count;
                randomCount = randomCount > size ? size : randomCount;
                //List values = Enumerable.ToList(allList.Keys);
                while (newList.Count < randomCount)
                {
                    TKey tk = allList[rand.Next(size)];
                    if (!newList.Contains(tk))
                    {
                        newList.Add(tk);
                    }
                }
                return newList;
            }

  • 相关阅读:
    jenkins安装和部署
    model.fit回调函数使用
    花旗金融技术岗社招内推
    docker的疑难杂症
    接口测试神器Apifox究竟有多香?
    利用无线通讯技术优化传统斗轮机作业方式
    java基于Springboot+vue的健身房课程预约平台 element
    【190】Java8利用红黑树实现Map
    Pytorch从零开始实战21
    VUEX版数字求和案例,附带vuex工作执行顺序图
  • 原文地址:https://blog.csdn.net/JLX_Sir/article/details/126126911