views:

56

answers:

4

I'm attempting to create an order number for customers to use. I will have multiple machines that do not have access to the same database (so can't use primary keys and generate a unique ID).

I will have a unique string that I could use for a seed for some algorithm that will generate a unique looking alphanumeric ID # for the order number. I do not want to use this unique string as the order # because its contents would not be appropriate in appearance for a customer to use for order #.

Would it be possible to combine the use of a GUID & my unique string with some algorithm to create a unique order #? Open to any suggestions.

A: 

Just use a straight up guid/uuid. They take into account the mac address of the network interface to make it unique to that machine.

http://en.wikipedia.org/wiki/Uuid

Matt Williamson
A: 

You can use ids and as a primary key if you generate they id from a stored procedure (or perhaps in Oracle using a sequence).

What you have to do is make each machine generate in a different range e.g. machine a from 1 to 1million, machine B from 1000001 to 2000000 etc.

Mark
A: 

You say you have a unique string that would not be 'appropriate' to show to customers.

If it's only inappropriate and not necessary i.e. security/privacy related you could just transform it somehow. A simple example would be Rot13

But generally I too would suggest using UUID (but version 4) for random numbers. The probability for generating duplicates is extremely low and there are libraries for many programming languages available.

zockman
+1  A: 

If you have a relatively small number of machines and each one can have it's own configuration file or setting, you can assign a letter to each machine (A,B,C...) and then append the letter onto the order number, which could just be an auto-incrementing integer in each DB.

i.e.

Starting each database ID at 1000:
1001A // First  order on database A
1001B // First  order on database B
1001C // First  order on database C
1002A // Second order on database A
1003A // Third  order on database A
1004A // etc...
1002B
1002C

Your order table in each database would have an ID column (integer) and "machine" identifier (character A,B,C...) so in case you ever needed to combine DBs into one, each order would still be unique.

Michael Butler