Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (6 votes)
See more:
how to generate 10 million unique numbers using alpha numerics?
hai need a method to generate 10 million unique numbers using .net





Thanks advance.
Posted
Comments
CPallini 17-Sep-14 5:05am    
Could you please elaborate?
sateesh kumar nemalikanti 17-Sep-14 5:10am    
thanks Cpallini ,ineed to generate random numbers.upto 10 million in those duplicates must not be repeat. and generated number length must be static for all 10 millions.
Richard MacCutchan 17-Sep-14 5:23am    
How about using 1 to 10,000000 and convert to a fixed length string.
sateesh kumar nemalikanti 17-Sep-14 5:33am    
hai go through below article ,and in this article only 1 million unique numbers are generated but i need 10 millions .http://www.codeproject.com/Articles/14403/Generating-Unique-Keys-in-Net
Richard MacCutchan 17-Sep-14 5:51am    
If the article does not do exactly what you need then either modify the code or ask the author for help.

This outputs '00000' as first number and '5yc1r' as 10000000th number

C#
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];
          }
        }
      }
    }
  }
}
 
Share this answer
 
v3
Comments
sateesh kumar nemalikanti 17-Sep-14 6:30am    
hai cpallini, thanks for your help,

But i need to use that number as a unique id.
i need a method that will produce unique id every time i call that method.id should be unique for upto 100,00,000 ids.

sorry for inconvenience this is my exact requirement.
upto 60, 00,000 also acceptable please help me any one thanks
CPallini 17-Sep-14 7:26am    
Does your id need to be random, in the sequence?
sateesh kumar nemalikanti 17-Sep-14 9:37am    
yes it is random or sequence, but whenever i call it will give a unique id and id should not match with the previously generated ids.
CPallini 17-Sep-14 9:46am    
My code gives you 10000000 different alphanumeric codes corresponding to numbers in the 0..9999999 range.
You might:
1. Modify it in order to give you the alphanumeric code corresponding to a given number (in the 0..9999999 range).
2. Randomly extract, without repetition, a number in the 0..9999999 range and use the extracted number to retrieve the corresponding alphanumeric sequence.

Point 2 is tricky, because you have to somehow record all the previous extracted numbers.
In my tip:
http://www.codeproject.com/Tips/54678/Random-extraction-of-cards-from-a-deck
You may find the algorithm used for random extraction without repetitions.
sateesh kumar nemalikanti 17-Sep-14 9:51am    
i need one id at a time but it gives 10000000 at a time.
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.
 
Share this answer
 
Comments
sateesh kumar nemalikanti 17-Sep-14 5:19am    
i need 10 million records sandeep. and repetation must not be allowed and generated number length must be static for all 10 millions.
C#
string[] TenMillionsId = new string[10000000];

for (int i = 0; i < 10000000; i++)
{
    Guid h = Guid.NewGuid();
    TenMillionsId[i] = h.ToString();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900