zoukankan      html  css  js  c++  java
  • 生成随机字母数字组合

    //生成随机字母数字组合
    public static string CreateRandom(int codeCount)
    {
    string allChar = "2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,m,n,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,U,V,W,X,Y,Z";
    
    string[] allCharArray = allChar.Split(',');
    string randomCode = "";
    int temp = -1;
    Random random = new Random();
    for (int i = 0; i < codeCount; i++)
    {
    if (temp != -1)
    {
    random = new Random(i * temp * (int)DateTime.Now.Ticks);
    }
    int t = random.Next(35);
    if (temp == t)
    {
    return CreateRandom(codeCount);
    }
    temp = t;
    randomCode += allCharArray[temp];
    }
    return randomCode;
    }
    codeCount代表需要生成的字符串长度
  • 相关阅读:
    基本内置类型
    多维数组
    数组
    迭代器
    标准库类型 vector
    标准库类型 string
    运算符优先级表
    类型转换
    sizeof 和逗号运算符
    位运算符
  • 原文地址:https://www.cnblogs.com/huangfenggu/p/4449678.html
Copyright © 2011-2022 走看看