For our online shop, we are giving out coupon codes (also called "promo code" or "voucher code").

Currently, these codes look like an insane developer has designed the format:


In fact that insane developer was me. I've used a GUID.

Now I'm seeking for a (at least slightly) more usable format.

I can imagine of something like YouTube video URLs:


Or just the current timestamp in ticks:


Or the current UNIX epoch time:


Or maybe some prefix to identify our product? Like e.g.:


My question:

How would you "design" the format/syntax of a coupon code?

Update 1:

I forgot to mention: We are giving out multiple different coupons. So something like "BUYIT" or other meaningful strings would not fit. I guess we need some random part.

  • 2
    What are the functionality requirements of the coupons? Do you generate a unique coupon for individual users?
    – user31143
    Commented Nov 5, 2014 at 16:47
  • @dan1111 yes, unique coupons.
    – Uwe Keim
    Commented Nov 5, 2014 at 17:38

3 Answers 3


If you need a lot of different unique codes it matters whether the user will have to manually type it in, and it will have to be generated algorithmicly.

Typed in Manually

For something they'll have to type in, and still sufficiently random, I've done this before by generating a string like GHJ5-JKG4.

Start by picking a random number between 0 and 31. (A-Z, 0-9, and take away 1, 0, I, O). Append that character to a string. so, g then h then j etc. You'll have ghj5jkg4 using the above example.

Check that string for inappropriate language. You don't want to randomly generate something like 1fuck3r5. As suggested in the comments, removing just vowels may be sufficent, especially if you don't use numbers.

Convert it to uppercase GHJ5JKG4, then store it in a DB. When displaying it to the user split the string in half separated by a hyphen GHJ5-JKG4 as people have a hard time remembering more than 4 characters.

When you check to see if it's valid, just strip non alphanumeric characters and lookup GHJ5JKG4 in your DB.

Unique code in email

You can get away with a longer string. Append the first ten characters of the MD5 hash of the current unix timestamp to a keyword for example.


Non Unique Code

Whatever looks nice!

FREESHIPPING from @RomC being a great example.

  • 2
    In this article, the author recommends to simple remove all vowels (a, e, i, o, u) to get rid of possible offensive words.
    – Uwe Keim
    Commented Nov 6, 2014 at 6:43
  • 1
    Heh, true enough. If you don't use numbers either that definitely works.
    – user57078
    Commented Nov 6, 2014 at 6:49

Let’s say you need a million codes tops. We’ll use a friendly scheme that has a milliard/billion possible combinations, but could be scaled up easily, so not every possible combination yielded a valid coupon code.

Get a list of 1000 short and frequent non-vulgar words, preferably from the same category, e.g. just nouns. Randomize their order. Assign to each a unique zero-padded three-digit number from 0 through 999 (could be the line number in a text file decreased by one).

Define a pattern to make only one in thousand numbers valid, e.g. every fourth digit is the check digit for the preceding three digits. Regroup by digit triplets. Select the words from your secret list that are identified by these numbers.

123_456_789_ – 1+2+3=6; 4+5+6=15, 1+5=6; 7+8+9=24, 2+4=6
123 645 667 896
rabbit tennis engine water

These words are easier remembered and typed (and spelling-corrected) than random numbers.

You can even internationalize this with word lists for other languages that arbitrarily coded the same numbers.

Garten Waage Müll Norden

Accept words in any capitalization. Throw away digits and punctuation.

This is just from the top of my head. Ask mathematicians whether a single check digit would suffice, whether you should use smaller or larger lists or if the word number should depend on the word position (i.e. 000000000 results in four different words). My only point is, change random letter and digit sequences into simple words. A very short list of words could be populated with ones meaningful to the business of the site.


Without any additional rules that would define what values can be used for a coupon code (or any restrictions), I recommend something that would be (1) easy to remember and (2) something that sort of describes the kind of discount that can be obtained.


WIDGET123 (Product name like you suggested - at least it implies that the coupon code is for that specific product only).

  • Thank you! I've updated my question. Actually I need lots of different codes, so probably I need some random stuff in the code?!?
    – Uwe Keim
    Commented Nov 5, 2014 at 15:48
  • 1
    Why don't you just tie the code to the email account so they are unique? Takes the burden off the user.
    – Mark Sloan
    Commented Nov 8, 2014 at 0:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.