Mar*_*ers 13
尝试将数字构建为字符串,并使用HashSet确保它们是唯一的:
Random random = new Random();
HashSet<string> ids = new HashSet<string>();
while (ids.Count < 25)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 10; ++i)
{
sb.Append(random.Next(10));
}
ids.Add(sb.ToString());
}
Run Code Online (Sandbox Code Playgroud)
示例输出:
7895499338 2643703497 0126762624 8623017810 ...etc...
该类HashSet存在于.NET 3.5及更高版本中.