C#生成随机数实例

2021-04-23 16:35

阅读:518

///

/// 生成num位数验证码  用于短信验证功能

///

public static Random rand = new Random();

public static string getCode(int num)

{

string result = “”;

string s = “uabcdefghijklmnopqrstuvwxyz0123456789”;

for (int i = 0; i

{

int k = ((rand.Next(1, 36) + i * 6) % 36) + 1;

result = string.Format(“{0}{1}”, result, s[k]);

} return result;

}


评论


亲,登录后才可以留言!