生成随机数
1. 代码
public static string GetRandom(int codeLenth)
{
while (true)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < codeLenth; i++)
{
if (i == 0)
sb.Append(new Random().Next(9) + 1); // first field will not start with 0.
else
sb.Append(new Random().Next(10));
}
return sb.ToString();
}
}
2. 用法
GetRandom(10) // 长度
网友评论