Creating a Unique ID for a Report Barcode

What is a robust way to generate a UID to use as a barcode identifier in a report. I did have the barcode representing the information directly, but now there is too much info to encode as a barcode. Now I must associate the data with a UID in my database to get the info I need when I scan. Looking for suggestions on the best way to generate the UID.

EDIT: The UID will be entered into the database along with the associative data in a button script.

from java.util import UUID
uid = UUID.randomUUID().toString()

Cool, it generated too long of uuid though for my barcode usage so I used this instead

from java.util import UUID
uid = UUID.randomUUID().getMostSignificantBits()
print uid

my results went from something like this


to this


Do I have to worry about any collisions with this method?

Not significantly - the randomUUID() function is generating a “true random” (type-4) UUID, so either slice of the 128-bits should be equivalently random. Collisions within a 64-bit space should be incredibly unlikely.

1 Like