Based on Deepak's excellent blog post about adding discount codes, we decided to take it one step further and write a module. The CiviEvent Discount module has an admin interface to manage discount codes and the ability to link them to one or more events. Combined with the recent ability to access price sets from hook_civicrm_buildAmount the module also supports adding discount codes to events with price sets.
We just added the project to d.o. this morning, so the dev release may not show up until tomorrow. In addition, this was developed mostly as a prototype for a client we're currently working with so we haven't flushed out all the requirements (or bugs) yet.