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 1036181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:39:44+00:00 2026-05-16T14:39:44+00:00

i want to generate a sequence of unique random numbers in the range of

  • 0

i want to generate a sequence of unique random numbers in the range of 00000001 to 99999999.

So the first one might be 00001010, the second 40002928 etc.

The easy way is to generate a random number and store it in the database, and every next time do it again and check in the database if the number already exists and if so, generate a new one, check it again, etc.
But that doesn’t look right, i could be regenerating a number maybe 100 times if the number of generated items gets large.

Is there a smarter way?

EDIT
as allways i forgot to say WHY i wanted this, and it will probably make things clearer and maybe get an alternative, and it is:
we want to generate an ordernumber for a booking, so we could just use 000001, 000002 etc. But we don’t want to give the competitors a clue of how much orders are created (because it’s not a high volume market, and we don’t want them to know if we are on order 30 after 2 months or at order 100. So we want to have an order number which is random (yet unique)

  • 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-05-16T14:39:44+00:00Added an answer on May 16, 2026 at 2:39 pm

    You could build a table with all the possible numbers in it, give the record a ‘used’ field.

    1. Select all records that have not been ‘used’
    2. Pick a random number (r) between 1 and record count
    3. Take record number r
    4. Get your ‘random value’ from the record
    5. Set the ‘used’ flag and update the db.

    That should be more efficient than picking random numbers, querying the database and repeat until not found as that’s just begging for an eternity for the last few values.

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

Sidebar

Related Questions

I want to generate 1M random (appearing) unique alphanumeric keys and store them in
Basically I want to generate random numbers that won't ever repeat for a very
I need to generate a deterministic (i.e. repeatable) sequence of pseudo-random numbers given an
I want to generate sequence of hexadecimal numbers starting with 07060504003020100 . Next number
I want to generate a sequence number starting from 00000001,00000002....(i need all these zero
I want to generate a random timestamp and add a random increment to it
I want to generate random integers between 0-9 (inclusive on both ends), but I
I want the first to be generated: @Id @Column(name = PRODUCT_ID, unique = true,
I am working on ASP.Net using C# I want to generate a sequence id
I want to generate a sequence like a multiplication table. So for a start

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.