<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## 1、生成指定返回隨機數 ``` /// <summary> /// 生成一個指定范圍的隨機整數,該隨機數范圍包括最小值,但不包括最大值 /// </summary> /// <param name="minNum">最小值</param> /// <param name="maxNum">最大值</param> public int GetRandomInt(int minNum, int maxNum) { return this._random.Next(minNum, maxNum); } ``` ## 用法 ``` RandomHelper r = new RandomHelper(); int k= r.GetRandomInt(111, 222);//返回111-222之間隨機數 ``` ## 2、生成一個0.0到1.0的隨機小數 ``` /// <summary> /// 生成一個0.0到1.0的隨機小數 /// </summary> public double GetRandomDouble() { return this._random.NextDouble(); } ``` ## 用法 ``` RandomHelper r = new RandomHelper(); double k = r.GetRandomDouble();//返回0.275322388520149 ``` ## 3、多數組隨機排序 ``` /// <summary> /// 對一個數組進行隨機排序 /// </summary> /// <typeparam name="T">數組的類型</typeparam> /// <param name="arr">需要隨機排序的數組</param> public void GetRandomArray<T>(T[] arr) { //對數組進行隨機排序的算法:隨機選擇兩個位置,將兩個位置上的值交換 //交換的次數,這里使用數組的長度作為交換次數 int count = arr.Length; //開始交換 for (int i = 0; i < count; i++) { //生成兩個隨機數位置 int randomNum1 = GetRandomInt(0, arr.Length); int randomNum2 = GetRandomInt(0, arr.Length); //定義臨時變量 T temp; //交換兩個隨機數位置的值 temp = arr[randomNum1]; arr[randomNum1] = arr[randomNum2]; arr[randomNum2] = temp; } } ``` ## 用法 ``` string[] sarr = { "1", "2", "3", "4", "5" }; RandomHelper r = new RandomHelper(); r.GetRandomArray(sarr);//對數組隨機排序 foreach (string s in sarr) { Response.Write(s);//返回 51324 這里僅僅是用法舉例,還有許多用法 } ``` ## 4、隨機生成不重復字符串數字和字母混和 ``` public string GenerateCheckCode(int codeCount) { string str = string.Empty; long num2 = DateTime.Now.Ticks + this.rep; this.rep++; Random random = new Random(((int)(((ulong)num2) & 0xffffffffL)) | ((int)(num2 >> this.rep))); for (int i = 0; i < codeCount; i++) { char ch; int num = random.Next(); if ((num % 2) == 0) { ch = (char)(0x30 + ((ushort)(num % 10))); } else { ch = (char)(0x41 + ((ushort)(num % 0x1a))); } str = str + ch.ToString(); } return str; } ``` ## 用法 ``` RandomHelper r = new RandomHelper(); string k= r.GenerateCheckCode(5); Response.Write(k);//返回8JBTD ``` ## 5、隨機生成不重復字符串(純數字) ``` // 一:隨機生成不重復數字字符串 private int rep = 0; public string GenerateCheckCodeNum(int codeCount) { string str = string.Empty; long num2 = DateTime.Now.Ticks + this.rep; this.rep++; Random random = new Random(((int)(((ulong)num2) & 0xffffffffL)) | ((int)(num2 >> this.rep))); for (int i = 0; i < codeCount; i++) { int num = random.Next(); str = str + ((char)(0x30 + ((ushort)(num % 10)))).ToString(); } return str; } ``` ## 用法 ``` RandomHelper r = new RandomHelper(); string k= r.GenerateCheckCodeNum(5); Response.Write(k);//返回 20447 ``` ## 6、從字符串里得到隨機規定的字符數[不推薦用] ``` /// <summary> /// 從字符串里隨機得到,規定個數的字符串. /// </summary> /// <param name="allChar"></param> /// <param name="CodeCount"></param> /// <returns></returns> private string GetRandomCode(string allChar, int CodeCount) { //string allChar = "1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,i,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"; string[] allCharArray = allChar.Split(','); string RandomCode = ""; int temp = -1; Random rand = new Random(); for (int i = 0; i < CodeCount; i++) { if (temp != -1) { rand = new Random(temp * i * ((int)DateTime.Now.Ticks)); } int t = rand.Next(allCharArray.Length - 1); while (temp == t) { t = rand.Next(allCharArray.Length - 1); } temp = t; RandomCode += allCharArray[t]; } return RandomCode; } ``` ## 用法
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看