Generate UUID (GUID) in Panorama X

I am new to Panorama X and would like to migrate datasets from both Filemaker and Xojo (SQLite) to Panorama X. These datasets use UUIDs for primary keys and I need to be able to generate a UUID when a new record is added.

My web search has pointed me to:
[Apple Developer Documentation]
and
[Apple Developer Documentation]

plus other sources such as
[https://www.cryptosys.net/pki/uuid-rfc4122.html]

I have no experience delving into the bit/byte/word/hex functions to brute-force this on my own (but I will try my best if I need to) so hope that a solution for Panorama X is already out there somewhere.

Advice please.
Kenneth James

This formula

hexstr(0x100000000*rnd())[-8,-1]+"-"+hexstr(0x10000*rnd())[-4,-1]+"-"
+hexstr(0x10000*rnd())[-4,-1]+"-"+hexstr(0x10000*rnd())[-4,-1]+"-"
+hexstr(0x100000000*rnd())[-8,-1]+hexstr(0x10000*rnd())[-4,-1]

Will give you an ASCII string that looks like this.

639CBDFC-B719-3E32-3E40-6246CA20E81D

This formula will give you 128 random bits of binary data.

longword(0x100000000*rnd())+longword(0x100000000*rnd())
+longword(0x100000000*rnd())+longword(0x100000000*rnd())

I’m not sure which you require.

Well, looking at this as a specialized string of text instead of a specialized group of hexadecimal numbers I came up with my own solution. This uses the looparray to generate the 36 characters consisting of the hex numbers and the “-” character. By first creating a ghost array of 35 carriage returns to drive the looparray to cycle 36 times we can then create each character in turn and account for the needed “-” characters as well as the “4” for the 15th character and reduced range used for the 20th character. Here is the code I used:

local x,y,z
x=rep(cr(),35)
y=""
z="0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F"
looparray x,cr(),element,index
    if index=9 or index=14 or index=19 or index=24
        y=y+"-"
    elseif index=15
        y=y+"4"
    elseif index=20
        y=y+randomarrayelement(arrayrange(z,9,12,","),",")
    else
        y=y+randomarrayelement(z,",")
    endif
endloop

Here are samples of the output:

Not as kosher as Dave’s solution but more in my wheelhouse.

Panorama X includes a function that generates UUID’s for you. It’s based on the Apple API that you found with your web search. This string is generated by the operating system and includes the host name, process ID, a time stamp and a counter, which ensures that the ID is unique for the network. Each time this function is called it returns a new unique string.

Awesome! And thank you! (Within an hour and on a Saturday morning no-less!)

Apparently, there is a standard for UUIDs ([http://www.ietf.org/rfc/rfc4122.txt]) that requires
1. Adjust certain bits according to RFC 4122 section 4.4 as follows:
1. set the four most significant bits of the 7th byte to 0100’B, so the high nibble is “4”
2. set the two most significant bits of the 9th byte to 10’B, so the high nibble will be one of “8”, “9”, “A”, or “B”.

However, since my use doesn’t involve interface with secure and/or certifiable applications, the above functions will suit me just fine.
Being able to generate these unique record ids opens up Panorama X for me. Thank you so much
KDJ
p.s. just noticed the post that there is a Panorama X function. Wonderful.

I noticed this too, and was working on a revised version that does that. The revised version for the ASCII string is

hexstr(0x100000000*rnd())[-8,-1]+"-"+hexstr(0x10000*rnd())[-4,-1]
+"-"+hexstr(randominteger(0x4000,0x4FFF))[-4,-1]+"-"
+hexstr(randominteger(0x8000,0xBFFF))[-4,-1]+"-"+hexstr(0x100000000*rnd())[-8,-1]
+hexstr(0x10000*rnd())[-4,-1]

I am curious. What would info(“guid”) be used for? And is there a function that reads the generated guid and extracts the host name, process id, time stamp and counter?

The description says

Returns a unique identifier string. This string is generated by the operating system and includes the host name, process ID, a time stamp and a counter, which ensures that the ID is unique for the network. Each time this function is called it returns a new unique string.

It would simply be used to identify something. The idea is to generate a string that is sufficiently complex, that you don’t need to worry about there being two with the same identifier.

shellscript({/usr/bin/uuidgen})will give you a string representing a version 4 UUID as specified in RFC-4122, i.e. a random number.

How do I get this information from the uuid?

How do I get this information from the uuid?

Not possible. The host name alone can have more characters than the whole ID, so this is a one-way calculation, purely meant to assure that nobody else arrives at the same number.