WEB开发网
开发学院WEB开发ASP.NET 得到随机字符串算法 阅读

得到随机字符串算法

 2006-12-01 17:18:08 来源:WEB开发网   
核心提示:using System;using System.Collections.Generic;using System.Text;namespace ring{ class PRogram { private static char[] constant = { '0','1',

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

namespace ring
{
   class PRogram
   {
     private static char[] constant =  {
     '0','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',
     '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'
     };
     public static string GetRandomStringByLength(int Length)
     {
       StringBuilder newRandom = new StringBuilder();
       Random rd = new Random();
       for (int i = 0; i < Length; i++)
       {
         newRandom.Append(constant[rd.Next(62)]);
       }
       return newRandom.ToString();
     }
     static void Main(string[] args)
     {
       //Get 10 random caracters string
       Console.WriteLine(GetRandomStringByLength(10));
       Console.ReadLine();
     }
   }
}
http://www.cnblogs.com/Ring1981/archive/2006/11/30/577400.html

Tags:得到 随机 字符串

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接