Random GUID generation in YottaDB

58 views
Skip to first unread message

Rob Tweed

unread,
Feb 21, 2025, 5:34:18 AMFeb 21
to Everything MUMPS
IRIS has a built-in function for generating Guids

I don't believe there's an equivalent in YottaDB.  Does anyone have an algorithm for generating them in YottaDB that they'd be willing to share?  Or perhaps there's a built-in function I've not spotted?

Thanks, Rob

Sam Habiel

unread,
Feb 21, 2025, 6:50:06 AMFeb 21
to Rob Tweed, Everything MUMPS

--
You received this message because you are subscribed to the Google Groups "Everything MUMPS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to everythingmum...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/everythingmumps/3024cac2-19b8-4206-b1c4-ca0db43cc088n%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rob Tweed

unread,
Feb 21, 2025, 7:18:59 AMFeb 21
to Everything MUMPS
Perfect! Thanks Sam!

K.S. Bhaskar

unread,
Feb 21, 2025, 7:52:38 AMFeb 21
to Everything MUMPS
For non-cryptographic uses, something like $zyhash($random(2147483646)+1_($random(2147483646)+1)_($random(2147483646)+1)_($random(2147483646)+1)) is probably adequate, given the $random() enhancements in r1.30 (the current YottaDB release is r2.02). For cryptographic uses, use bytes from /dev/random.

Regards
– Bhaskar

Matthew R. Wilson

unread,
Feb 21, 2025, 5:12:07 PMFeb 21
to K.S. Bhaskar, Everything MUMPS
Keep in mind that UUIDs aren't just random numbers, they are a
standardized thing with different versions that have different
properties. Even the "just generate random bits" version (UUIDv4) uses
6 of the 128 bits to indicate that it is, indeed, a v4 UUID. If you
are planning on interoperability with other systems that have
particular expectations around UUIDs (e.g. maintaining time sequence
when sorted, generating UUIDs being identifiable as belonging to a
particular namespace, etc.) you would need to use the correct version
and create it with the correct structure.

https://datatracker.ietf.org/doc/html/rfc9562

-Matthew
> To view this discussion visit https://groups.google.com/d/msgid/everythingmumps/52e5325d-b0b1-436e-81f6-b98ae6771d99n%40googlegroups.com.

Rob Tweed

unread,
Feb 22, 2025, 1:07:03 AMFeb 22
to Everything MUMPS
Yep I'm well aware of this.  All the more reason why, IMO, YottaDB should natively support their generation

K.S. Bhaskar

unread,
Feb 22, 2025, 10:43:43 AMFeb 22
to Everything MUMPS
Actually a version 4 UUID is random (https://en.wikipedia.org/wiki/Universally_unique_identifier), but yes, 6 bits are used to designate its version so it is not entirely random as I indicated.

Regards
– Bhaskar

Mark Sires

unread,
Feb 23, 2025, 11:40:36 AMFeb 23
to Everything MUMPS
One thing I like about YottaDB is they don't waste time or money recreating something that is readily available in Linux.  The following code uses the Linux uuidgen utility to generate a UUID.
UUID(optionstring) ;generate a UUID
 ;Options:
 ; -r, --random        generate random-based uuid
 ; -t, --time          generate time-based uuid
 ; -n, --namespace ns  generate hash-based uuid in this namespace
 ;                       available namespaces: @dns @url @oid @x500
 ; -N, --name name     generate hash-based uuid from this name
 ; -m, --md5           generate md5 hash
 ; -s, --sha1          generate sha1 hash
 ; -x, --hex           interpret name as hex string
 ;the option string should have all the desired  options together
 ; "-r -n @oid --name test --sha1"
 N UUID,CALL,%CIO,FILE,commandstring
 S %CIO=$I
 S optionstring=$G(optionstring)
 s commandstring="uuidgen "_optionstring
 S CALL="uuidgen"
 O CALL:(command=commandstring:noreadonly:stream:nofixed:nowrap)::"PIPE"
 U CALL R UUID:2
 U %CIO
 C CALL
 Q:$Q UUID Q
Reply all
Reply to author
Forward
0 new messages