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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:43:03+00:00 2026-05-13T07:43:03+00:00

I’ve found a number of different questions on generating UIDs, but as far as

  • 0

I’ve found a number of different questions on generating UIDs, but as far as I can tell, my requirements here are somewhat unique (ha).

To summarize: I need to generate a very short ID that’s “locally” unique, but does not have to be “globally” or “universally” unique. The constraints are not simply based on aesthetic or space concerns, but due to the fact that this is essentially being used as a hardware tag and is this subject to the hardware’s constraints. Here are the specifications:

Hard Requirements

  • The ID must contain only decimal digits (the underlying data is a BCD);
  • The maximum length of the ID is 12 characters (digits).
  • Must be generated offline – a database/web connection is not always available!

Soft Requirements

  • We’d like it to begin with the calendar year and/or month. As this does waste a lot of entropy, I don’t mind compromising on this or scrapping it entirely (if necessary).
  • IDs generated from a particular machine should appear sequential.
  • IDs do not have to sort by machine – for example, it’s perfectly fine for machine 1 to spit out [123000, 124000, 125000], and machine 2 to spit out [123500, 123600, 124100].
  • However, the more sequential-looking in a collective sense, the better. A set of IDs like [200912000001, 200912000002, 200912000003, …] would be perfect, although this obviously does not scale across multiple machines.

Usage Scenario:

  • IDs within the scope of this scheme will be generated from 10, maybe 100 different machines at most.
  • There will not be more than a few million IDs generated, total.
  • Concurrency is extremely low. A single machine will not generate IDs more often than every 5 minutes or so. Also, most likely no more than 5 machines at a time will generate IDs within the same hour or even the same day. I expect less than 100 IDs to be generated within one day on a given machine and less than 500 for all machines.
  • A small number of machines (3-5) would most likely be responsible for generating more than 80% of the IDs.

I know that it’s possible to encode a timestamp down to 100 ms or even 10 ms precision using less than 12 decimal digits, which is more than enough to guarantee a “unique enough” ID for this application. The reason I am asking this here on SO, is because I would really like to either try to incorporate human-readable year/month in there or encode some piece of information about the source machine, or both.

I’m hoping that someone can either help with a compromise on those soft requirements… or explain why none of them are possible given the other requirements.

(P.S. My “native” language is C# but code in any language or even pseudocode is fine if anybody has any brilliant ideas.)

Update:

Now that I’ve had the chance to sleep on it, I think what I’m actually going to do is use a timestamp encoding by default, and allow individual installations to switch to a machine-sequential ID by defining their own 2- or 3-digit machine ID. That way, customers who want to mess with the ID and pack in human-readable information can sort out their own method of ensuring uniqueness, and we’re not responsible for misuse. Maybe we help out by providing a server utility to handle machine IDs if they happen to be doing all online installations.

  • 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-13T07:43:04+00:00Added an answer on May 13, 2026 at 7:43 am

    How about yyMMddhhmmID?

    yy = two-digit year
    MM = two-digit month
    dd = two-digit day
    hh = two-digit hour (24-hour time)
    mm = two-digit minute
    ID = machine-specific ID
    

    Example: 0912113201 from machine with ID = 01.

    Alternatively (if you don’t like two-digit years (Y2K lol)), how about yyyyMMIDxxxx?

    yyyy = four-digit year
    MM = two-digit month
    ID = machine-specific ID
    xxxx = sequentially-incremented integer
    

    Example: 200912010001 from machine with ID = 01.

    As you said that each machine will only generate one identifier maximum every five minutes, this gives you room for 8,928 (24 * 31 * 60 / 5 = 8928) identifiers per month which will fit in xxxx. Here you could squeeze the year down to a three-digit year yyy (009, e.g.) if you needed an extra digit in the xxxx sequence or the machine ID.

    Both of these fit timestamp/machine ID as you requested.

    We all like concrete code:

    class Machine {
        public int ID { get; private set; }
        public Machine(int id) {
            ID = id;
        }
    }
    
     class IdentifierGenerator {
        readonly Machine machine;
        int seed;
        const int digits = 4;
        readonly int modulus;
        readonly string seedFormat;
        public IdentifierGenerator(Machine machine) {
            this.machine = machine;
            this.modulus = (int)Math.Pow(10, digits);
            this.seedFormat = new string('0', digits);
        }
    
        public string Generate() {
            string identifier = DateTime.Now.ToString("yyyyMM") 
                                    + machine.ID.ToString("00") 
                                    + seed.ToString(seedFormat);
            seed = (seed + 1) % modulus;
            return identifier;
        }
    }
    
    Machine m = new Machine(1);
    IdentifierGenerator gen = new IdentifierGenerator(m);
    Console.WriteLine(gen.Generate());
    Console.WriteLine(gen.Generate());
    

    Outputs:

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I've tracked down a weird MySQL problem to the two different ways I was
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string

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.