protected void Button1_Click(object sender, EventArgs e) { Response.Write(GenerateRandom(6).ToLower().ToString()); } private static char[] constant = { '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 GenerateRandom(int Length) { System.Text.StringBuilder newRandom = new System.Text.StringBuilder(constant.Length); Random rd = new Random(); for (int i = 0; i < Length; i++) { newRandom.Append(constant[rd.Next(constant.Length-1)]); } return newRandom.ToString().ToLower(); }
C# 中随机生成字母
最新推荐文章于 2025-01-01 00:15:00 发布
本文介绍了一种使用C#生成指定长度随机字符串的方法。通过定义字符集并利用Random类来从字符集中随机选取字符,最终生成一个全部由小写字母组成的随机字符串。

1227

被折叠的 条评论
为什么被折叠?



