Creating a barcode to scan and discount is fairy simple, ive done a tutorial on it if you search Ricks tutorials
The harder part is having is randomly print 10% of time
What would be easier is a separate ticket template just with the discount voucher with barcode on, then set that to print at certain times, maybe every 20 tickets or something. It’s a little less random as it will happen every 20 but would be easier to do