Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8108167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:00:57+00:00 2026-06-06T01:00:57+00:00

I want to generate 1M random (appearing) unique alphanumeric keys and store them in

  • 0

I want to generate 1M random (appearing) unique alphanumeric keys and store them in a database. Each key will be 8 characters long and only the subset “abcdefghijk n pqrstuvxyz and 0-9” will be used.

The letters l,m,o and w are ditched. “m and w” are left out because of limited printing space, as each key will be printed on a product in a very small space. Dropping m and w enabled to increase the letter size with 2pt, improving readability. l and o were dropped because they are easily mixed up with 1, i and 0 at the current printing size. We did some testing characters 1,i, and 0 were always read correctly, l and o had to many mistakes. Capitals were left out for the same reason as ‘m and w”.

So why not a sequence? A few reasons: The keys can be registered afterwards and we do not want anyone guessing the next key in the sequence and register somebody else’s key. Appearance: we don’t need customers and competition to know we only shipped a few thousand keys.

Is there a practical way to generate the keys, ensure the uniqueness of each key and store them in a database? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T01:00:58+00:00Added an answer on June 6, 2026 at 1:00 am

    Edit: @CodeInChaos pointed out a problem: System.Random isn’t very secure, and the sequence could be reproduced without a great deal of difficulty. I’ve replaced Random with a secure generator here:

    var possibilities = "abcdefghijknpqrstuvxyz0123456789".ToCharArray();
    int goal = 1000000;
    int codeLength = 8;
    var codes = new HashSet<string>();
    var random = new RNGCryptoServiceProvider();
    while (codes.Count < goal)
    {
        var newCode = new char[codeLength];
        for (int i = 0; i < codeLength; i++)
            newCode[i] = possibilities[random.Next(possibilities.Length)];
        codes.Add(new string(newCode));
    }
    // now write codes to database
    
    static class Extensions
    {
        public static byte Next(this RNGCryptoServiceProvider provider, byte maximum)
        {
            var b = new byte[1];
            while (true)
            {
                provider.GetBytes(b);
                if (b[0] < maximum)
                    return b[0];
            }
        }
    }
    

    (the Next method isn’t very fast, but might be good enough for your purposes)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to generate unique random, N-valued key. This key can contain numbers and
I want to generate a random string of about 5 characters long. I can
Possible Duplicate: PHP: How to generate a random, unique, alphanumeric string? i want to
I want to generate a random list of strings containing only alphanumeric characters. The
I want to write a program that will generate random notes and draw them
Given an array of size n I want to generate random probabilities for each
I want to generate a random password of 15 characters that contains BOTH numbers
i want to generate a sequence of unique random numbers in the range of
I want to generate 2n-1 random integers in the range [1,n] with each element
I want to generate random integers between 0-9 (inclusive on both ends), but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.