• 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;
            }

  • 相关阅读:
    一文搞懂Zookeeper原理
    Ubuntu编辑.bashrc
    配置OpenGL
    GAN-Tutorial procedural record
    【技术分析】恶意 SPL 代币识别指南
    LeetCode·435.无重叠区间·贪心
    js input 正则保留2位小数中文拼音输入问题 + 限制输入整数的方案
    第二周学习报告
    爱上开源之golang入门至实战第三章-性能分析-分析数据
    [SQL开发笔记]SQL 别名:为表名称或列名称指定别名
  • 原文地址:https://blog.csdn.net/JLX_Sir/article/details/126126911