My Rails app needs to generate electronic coupons for users. Each coupon given should have a unique coupon code that can be redeemed on our system.
For example a cou
Get an epoch timestamp and base encode it.. as long as you save a record of it somewhere you can compare if it's valid when it's used.
If you need it to be enterable by hand you can always .string() it down to first 8 or so characters.
Draw random numbers using a proven generator (http://en.wikipedia.org/wiki/List_of_pseudorandom_number_generators).
Assume you deliver 333 coupons per day and these are valid for 30 days. So you have to store 10000 numbers and ensure that a forger cannot find one by chance.
If your numbers have 10 significant digits (~32 bits, ~8 hex digits), the probability of such an event is one over a million. Of course you can use more.