I need help on giving digital content after purchase

hello, I am trying to create unique purchasable codes, I would like to take them from an array variable = [] but I don’t know how to do it.

my goal is to create a purchasable product containing a random code from the ones entered which is given to the buyer once they have purchased the product.

if you could give me some hints on how to do this i would be grateful. thank you.