一个序列号生成器

public string CreateSerialNumber(int strLength)
{
    if (strLength < 1)
        strLength = 4;

    string str = string.Empty;
    string codeStr = string.Empty;
    string guidStr = Guid.NewGuid().ToString().Replace("-", "");
    int guidStrLen = guidStr.Length;
    Random rnd = new Random(int.Parse(DateTime.Now.ToString("MMddHHmmsss")));

    for (int i = 0; i < strLength; i++)
    {
        int index = rnd.Next(0, guidStrLen - 1);
        str += guidStr.Substring(index, 1);
    }

    return str.ToUpper();
}

 

posted @ 2012-04-24 09:32  AlanCoder  阅读(139)  评论(0)    收藏  举报
View Code