(精华)2020年6月26日 C#类库 Random随机数帮助类

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Core.Util
{
    /// 
    /// Random随机数帮助类
    /// 
    public static class RandomHelper
    {
        private static Random _random { get; } = new Random();

        /// 
        /// 下一个随机数
        /// 
        /// 最小值
        /// 最大值
        /// 
        public static int Next(int minValue, int maxValue)
        {
            return _random.Next(minValue, maxValue);
        }

        /// 
        /// 下一个随机值
        /// 
        /// 值类型
        /// 值的集合
        /// 
        public static T Next<T>(IEnumerable<T> source)
        {
            return source.ToList()[Next(0, source.Count())];
        }
    }
}

你可能感兴趣的:(#,C#类库/扩展方法)