Do you really need it to be random? A very simple solution is to insert a field where you need the code with Insert
→ Field
→ Other
, choosing Type Time, Select Time [not Time(fixed)], Format Additional Formats [HH]MMSS. Of course, it is not very random, there is no check key but it is guaranteed to never be the same.
@robleyd’s solution has the drawback that if you print twice, you’ll get the same sequence the second time. It is superior to mine if you want to record the codes in case they are associated with different discounts and you want to make sure they are used only once.
EDIT
To get unique codes, you must print flyers one by one; do not set Number of copies higher than 1 otherwise the code will be the same on all copies. If you print manually during a single session, strike F9
between each print job to update field contents.
Alternatively, you can write a small shell script to loop over launch-flyer-with-LO/print/quit a certain number of time. Eventually insert a (random?) pause so that time changes between copies. This is most convenient for an overnight job.