# Creating a Unique ID for a Report Barcode

**URL:** <https://forum.inductiveautomation.com/t/creating-a-unique-id-for-a-report-barcode/21514>\
**Category:** Ignition\
**Created:** [December 19, 2018, 7:52pm UTC](https://forum.inductiveautomation.com/t/creating-a-unique-id-for-a-report-barcode/21514 "2018-12-19T19:52:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [December 19, 2018, 7:52pm UTC](https://forum.inductiveautomation.com/t/creating-a-unique-id-for-a-report-barcode/21514/1 "2018-12-19T19:52:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 19, 2018, 8:25pm UTC](https://forum.inductiveautomation.com/t/creating-a-unique-id-for-a-report-barcode/21514/2 "2018-12-19T20:25:54Z")

</div>

[https://docs.oracle.com/javase/7/docs/api/java/util/UUID.html](https://docs.oracle.com/javase/7/docs/api/java/util/UUID.html)

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

```

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [December 19, 2018, 8:46pm UTC](https://forum.inductiveautomation.com/t/creating-a-unique-id-for-a-report-barcode/21514/3 "2018-12-19T20:46:55Z")

</div>

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

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

```

my results went from something like this

```auto
11cda468-aa5b-4c5f-baf0-d16a39027c2e

```

to this

```auto
349008164283105895

```

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 19, 2018, 8:48pm UTC](https://forum.inductiveautomation.com/t/creating-a-unique-id-for-a-report-barcode/21514/4 "2018-12-19T20:48:48Z")

</div>

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.
