Not an ideal solution for your use case, but could be useful. I’m using this code from Gravity Wiz to auto-generate one-time use gift certificate codes that a user purchases on the site. You might be able to repurpose this in some way to auto-generate codes for your users.