zoukankan      html  css  js  c++  java
  • 随机数生成

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace Exam.BLL
    {
        
    /// <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();
        }

    }

  • 相关阅读:
    hive中使用正則表達式不当导致执行奇慢无比
    C/C++实现正负数四舍五入
    EEPlat的控制器概念
    由于好高骛远所以半途而废(张作作)
    新辰:关于“网络推广不能仅仅依靠网络”的详解
    SQL的事务回滚操作带案例分析
    怎样把引用的jar包和本项目一起导出成jar文件
    A星算法(Java实现)
    Hadoop之——HBASE结合MapReduce批量导入数据
    Spring MVC 数据验证——validate编码方式
  • 原文地址:https://www.cnblogs.com/xhan/p/1055963.html
Copyright © 2011-2022 走看看