views:

65

answers:

4

Considering the following:

a) you want some confidentiality (as in not telling everybody how many orders you've received).

b) you want a check digit (e.g., using the Verhoeff algorithm) at the end so you can easily tell misspells and help dealing with errors when scanning barcodes, if this is the case.

c) you've to consider time so consumers can sort the order of the orders.

d) should it be all numeric or hexdec, etc?.

e) something that your consumer can say over the phone to the support team and is just enough for identifying the order without the staff having to ask for e-mail, etc, because of security concern.

I'd love to hear some opinions.

PS: any algorithm designed for solving this problem also would be considered a valid answer for me.

+1  A: 

How about random string of whatever length you see fit? Use characters that aren't easily confused with other characters for reading over the phone purposes. So on each order call something like:

    public static string GetRandomString(int length)
    {
        char[] chars = "ACDEFGHJKMNPQRTWXY34679".ToCharArray();
        var crypto = new RNGCryptoServiceProvider();
        var data = new byte[length];
        crypto.GetNonZeroBytes(data);
        var result = new StringBuilder(length);
        for (int i = 0; i < data.Length; i++)
        {
            result.Append(chars[data[i] % chars.Length]);
        }

        return result.ToString();
    }

Guessing 8 characters returned from the above method is a 1/282429536481 chance. And you'll keep integrity in the db with a unique constraint right?

jayrdub
A: 

You could use a GUID. To shrink it down to a customer friendly string it would be worth running the value through a Base32 converter which would result in a string containing 26 characters of A-Z and digits 2-7

To meet your other criteria, you could append a check digit to the guid value, and you'd probably need a separate genuine incremental order number in the database to guarantee uniqueness and allow natural indexing/sorting.

PaulG
you only need the first few characters of GUID to really narrow down the actual entry, look at how Git only needs the first 4 - 5 characters to uniquely identify a commit. you just ask the customers for a few more characters until you get a match with their name.
fuzzy lollipop