0

The short version: How can I use minutes since a recent date and 2 sets of known numbers from 0-255 to guarantee a unique 7 digit number?

Long version: I'm trying to generate a unique number or string that is guaranteed to be unique for at least 5 years, preferably 10 years that will only be 7 digits. This is for naming computers hostnames in AWS and we have servers that come and go daily based on need. The maximum a windows hostname can be is 15 characters and my company requires the first 8 characters be set, so I only have 7 characters to use to guarantee uniqueness.

What I've figured out so far is that I will take the number of minutes since January 1st, 2018 and convert it to Base32, which takes of the first 5 characters.

Now, that leaves me with the final 2 characters. I'm trying to use an attribute of the server that I know won't conflict, which is the private IP address. I'm trying to use the last 2 octets of the private IP address. The last 2 octets of the IP address can be 0 - 255.

Is there some mathematical operation I can do to the last 2 octets of the IP address or combine them in some way with the number of minutes since Jan 1, 2018 that would guarantee uniqueness?

luhlig
  • 1
  • So you want some sort of hash function, but I'm a little confused by what you mean "unique." I understand that you don't want conflicts, but do you mean unique to the minute? Like, every minute generates a new unique number? – Carser Jul 05 '18 at 15:48
  • You have fifteen digits to play with. You say that eight of them are taken. That leaves seven. You use five of them with your date scheme. That leaves two. You have 256 x 256 = 65536 possibilities from the IP address. But there is no way to get two unique digits -- a hundred possibilities -- out of 65 thousand unique inputs! – Eric Lippert Jul 05 '18 at 15:59
  • The typical way one generates a small unique number is a counter. Every time you make a new machine, increment the counter. With seven digits, that's ten million machines. How many million machines do you make per year? (AWS probably has a counter service; perhaps you should be using it?) – Eric Lippert Jul 05 '18 at 16:00
  • 1
    If you have a value that you already know won't conflict -- the IP address -- then why are you mucking around with the date scheme in the first place? Just use the IP! – Eric Lippert Jul 05 '18 at 16:01
  • @EricLippert I don't have to use 5 with my date scheme, I can change that or incorporate that into something else. In regards to your counter question, I could implement a counter, however that would require storing in a centralized the location the utilized values, which I do not want to do. Your 3rd question regarding why not just use the IP address is because we only have 256 IP addresses available. The computers come and going on an hourly basis but there can only be 256 at a time. The IP addresses can be reused, however the hostnames cannot. – luhlig Jul 05 '18 at 16:05
  • The private IP address uses five decimal digits. That leaves you two characters to use for sequencing. If you use letters (upper and lower case) and digits, that gives you $62^2$ possibilities. You can use days since January 1, 2018 and go for 10 years. – saulspatz Jul 05 '18 at 16:11
  • Are you restricted to decimal digits? Why not convert the minutes to base 36 or even base 62? – saulspatz Jul 05 '18 at 16:21

0 Answers0