如何使用alpha数字生成1000万个唯一数字? [英] how to generate 10 million unique numbers using alpha numerics?
本文介绍了如何使用alpha数字生成1000万个唯一数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用字母数字生成1000万个唯一数字?
hai需要一种方法来生成1000万个唯一数字使用.net
谢谢提前。
how to generate 10 million unique numbers using alpha numerics?
hai need a method to generate 10 million unique numbers using .net
Thanks advance.
推荐答案
使用GUID生成唯一的字母数字值。
32个字符。
OR
选择3个字符和4个数字,然后使用序列数值并增加数字值。
for first for first char {
for second for second char {
For for second for second char {
For循环for Numbers {
}
}
}
}
所有你需要做的就是将数据保存到永久数据库之后的存储就像生成1000条记录一样。
Use GUID to generate unique alpha numeric value.
32 chars.
OR
Choose 3 char and 4 numbers and go with serial numeric value and increase value of number.
For loop for first char {
For loop for second char {
For loop for second char {
For loop for Numbers {
}
}
}
}
All you need to do is just save data to permanent storage like database after a chunk of number generated like 1000 records.
输出'00000'
作为第一个数字和'5yc1r'
为10000000 th 号码
This outputs'00000'
as first number and'5yc1r'
as 10000000th number
static void Main(string[] args)
{
const int BASE=36;
char[] base36 = {'0','1','2','3','4','5','6','7','8','9','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'};
int[] idx = { 0, 0, 0, 0, 0 };
for (int n = 0; n < 10000000; ++n)
{
string s = string.Empty + base36[idx[4]]+ base36[idx[3]] + base36[idx[2]] + base36[idx[1]] + base36[idx[0]];
Console.WriteLine(s);
++idx[0];
if (idx[0] == BASE)
{
idx[0] = 0;
++idx[1];
if (idx[1] == BASE)
{
idx[1] = 0;
++idx[2];
if (idx[2] == BASE)
{
idx[2] = 0;
++idx[3];
if (idx[3] == BASE)
{
idx[3] = 0;
++idx[4];
}
}
}
}
}
}
string[] TenMillionsId = new string[10000000];
for (int i = 0; i < 10000000; i++)
{
Guid h = Guid.NewGuid();
TenMillionsId[i] = h.ToString();
}
这篇关于如何使用alpha数字生成1000万个唯一数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文