⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 randomnumberhelper.cs

📁 本在线考试系统采用了面向对象的分析和设计
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;

namespace ExaminationSystem.BLL.Utils
{

        /// <summary>
        /// 帮助生成随机数类
        /// </summary>
        class RandomNumberHelper
        {
            /// <summary>
            /// 从指定列表中随机取出指定个数整数以新列表返回
            /// </summary>
            /// <param name="sourceList">原列表</param>
            /// <param name="selectCount">要选取个数</param>
            /// <returns>新列表</returns>
            public static IList<int> RandomSelect(IList<int> sourceList, int selectCount)
            {
                if (selectCount > sourceList.Count)
                    throw new ArgumentOutOfRangeException("selectCount必需大于sourceList.Count");
                IList<int> resultList = new List<int>();
                for (int i = 0; i < selectCount; i++)
                {
                    int nextIndex = GetRandomNumber(1, sourceList.Count);
                    int nextNumber = sourceList[nextIndex - 1];
                    sourceList.RemoveAt(nextIndex - 1);
                    resultList.Add(nextNumber);
                }
                return resultList;
            }
            /// <summary>
            /// 生成一个整数大于等于最小值,小于等于最大值
            /// </summary>
            /// <param name="minValue">最小值</param>
            /// <param name="maxValue">最大值</param>
            /// <returns>整数,大于等于最小值,小于等于最大值</returns>
            public static int GetRandomNumber(int minValue, int maxValue)
            {
                return random.Next(minValue, maxValue + 1);
            }
            private static Random random = new Random();
        }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -