This post is in the context of a PostgreSQL stored procedure. If you have ready access to a block cipher, you could use one with an appropriate block size; e.g., 32-bit RC5 for coupon codes, 128-bit AES for activation keys, or 64-bit Blowfish for something in between.