C#生成随机字符串的实例
程序员文章站
2023-12-14 08:36:28
复制代码 代码如下:/// /// 生成随机字符串 /// ...
复制代码 代码如下:
/// <summary>
/// 生成随机字符串
/// </summary>
private class randomstringgenerator
{
static readonly random r = new random();
const string _chars = "0123456789";
public static string getrandomstring()
{
char[] buffer = new char[5];
for (int i = 0; i < 5; i++)
{
buffer[i] = _chars[r.next(_chars.length)];
}
return new string(buffer);
}
}