Hi Patrick,
If you look back, there are quite a few discussions of this from the past, and the takeaways are still the same today.
If you're willing to have one discount code per Lead, ever — not one code per Program Member, i.e. Lead-Program combo — then you can use the Marketo Unique Code field, which already exists on every lead.
If you need unique Program Member codes, it gets more complicated.
The most robust way to do this is to use a webhook-compatible service that can pop unique codes off a "stack" — a file you store in Design Studio.
As a kind of quirky-but-cool substitute, you might create a unique code to identify your Program (I would say to use the Program ID, but that might be leaked at some point in a URL, so best practices would say no to that). Store that code in a {{my.token}}. Then, using Velocity, send someone the XOR of that {{my.token}} and their {{lead.Marketo Unique Code}}. The code would be something they'd never be able to figure out on their own, that is, even if they knew somebody else's email address, they couldn't generate a valid discount code.
EDIT: I'm going to be talking about this technique on one of my slides for MOPSCON this year, FYI!