Generate UUID (GUID) in Panorama X


#1

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:
[https://developer.apple.com/documentation/corefoundation/cfuuid-rci]
and
[https://developer.apple.com/documentation/corefoundation/1542189-cfuuidgetconstantuuidwithbytes]

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


#2

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.


#3

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.


#4

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.


#5

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.


#6

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]

#7

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.


#8

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.


#9

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


#10

How do I get this information from the uuid?


#11

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.