设为首页 加入收藏 网站搜索 繁體中文 中国建站网 — 站长资源平台

得到随机字符串算法

来源网络收集 作者:佚名 时间:2007-4-25 23:30:38 该文得分0

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

相关文章
广告赞助
网友评论

共有 0 位网友发表了评论,平均得分: 0 查看完整内容

用户名:

分 值:100分 85分 70分 55分 40分 25分 10分 0分

内 容:

(注“”为必填内容。) 验证码: 验证码,看不清楚?请点击刷新验证码