国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#實現隨機數產生類實例

2020-01-24 02:06:25
字體:
來源:轉載
供稿:網友

本文實例講述了C#實現隨機數產生類。分享給大家供大家參考。具體分析如下:

這個類主要擴展的random的使用,對一個經常需要使用的隨機數生成進行了封裝,可以產生指定范圍內的隨機數,可以隨機生成字符串等

using System;namespace DotNet.Utilities{  /// <summary>  /// BaseRandom  /// 產生隨機數  ///  /// 隨機數管理,最大值、最小值可以自己進行設定。  /// </summary>  public class BaseRandom  {    public static int Minimum = 100000;    public static int Maximal = 999999;    public static int RandomLength = 6;    private static string RandomString = "0123456789ABCDEFGHIJKMLNOPQRSTUVWXYZ";    private static Random Random = new Random(DateTime.Now.Second);    #region public static string GetRandomString() 產生隨機字符    /// <summary>    /// 產生隨機字符    /// </summary>    /// <returns>字符串</returns>    public static string GetRandomString()    {      string returnValue = string.Empty;      for (int i = 0; i < RandomLength; i++)      {        int r = Random.Next(0, RandomString.Length - 1);        returnValue += RandomString[r];      }      return returnValue;    }    #endregion    #region public static int GetRandom()    /// <summary>    /// 產生隨機數    /// </summary>    /// <returns>隨機數</returns>    public static int GetRandom()    {      return Random.Next(Minimum, Maximal);    }    #endregion    #region public static int GetRandom(int minimum, int maximal)    /// <summary>    /// 產生隨機數    /// </summary>    /// <param name="minimum">最小值</param>    /// <param name="maximal">最大值</param>    /// <returns>隨機數</returns>    public static int GetRandom(int minimum, int maximal)    {      return Random.Next(minimum, maximal);    }    #endregion  }}

希望本文所述對大家的C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 会理县| 鄂托克旗| 客服| 普宁市| 隆子县| 珲春市| 栾城县| 祁阳县| 万全县| 沽源县| 安福县| 祁连县| 泰来县| 栾川县| 舞钢市| 永宁县| 织金县| 阜宁县| 黄龙县| 宁乡县| 临汾市| 凭祥市| 大埔区| 龙井市| 工布江达县| 浑源县| 阿尔山市| 游戏| 万安县| 彭水| 定日县| 云和县| 乌拉特后旗| 库伦旗| 日土县| 祁门县| 峡江县| 郴州市| 竹山县| 繁峙县| 乌审旗|