Web · real, tested code

Generate a UUID in Larzscript

Generate random (v4) and time-sortable (v7, ULID, nanoid) unique identifiers.

v7/ULID matter for anything that writes a lot of ids into a database index: sorting a batch of them as plain strings also sorts them by creation time, which a random v4 id can't do.

larzscript pkg install uuid

Code

import "uuid" as uuid

print(uuid.v4())
print(uuid.v7())
print(uuid.ulid())
print(uuid.nanoid())
Output
1e3b4dae-4c82-494e-a25b-4a26d0cf5dd7
019fc342-c9d0-7d2a-9f5a-dbe9710e80f6
01KZ1M5JEGC1GZA4MTS5STQY6V
0Nb1rFbSIrUBVz2U6d0ee