zoukankan      html  css  js  c++  java
  • 随机得到,规定个数的字符串

         #region

      /// <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;   }

      #endregion

  • 相关阅读:
    构建之法阅读笔记
    人月神话阅读笔记
    人月神话阅读笔记2
    人月神话阅读笔记
    第十周总结
    第九周总结
    进度日报10
    进度日报8
    进度日报7
    进度日报6
  • 原文地址:https://www.cnblogs.com/yyzyou/p/3793934.html
Copyright © 2011-2022 走看看