3

How do I create a UUID (= Universally unique identifier, or GUID = Globally Unique Identifier, Microsoft speak) in Livecode or Hypercard?

The aim of UUIDs is to give practically unique keys to pieces of information without a central coordination.

References

Community
  • 1
  • 1
z--
  • 2,186
  • 17
  • 33

4 Answers4

3

If you're on a Unix (like Linux or MacOS), you could use the shell() function to call the uuidgen Terminal command. It should be something like

put shell("uuidgen") into theUUID

That's a bit heavy-handed (creates a shell, runs a command line application in it, then quits it again), but will work on older LiveCode versions, and isn't that different from what a shell script does.

In HyperCard, you'd have to use AppleScript, either in an object whose script is set to AppleScript, or using the "do X as AppleScript" command. Not sure if AppleScript can natively build UUIDs, but if it can't, AppleScript can be used to run shell scripts. (The shell() function doesn't exist in HyperCard, it was invented by SuperCard, IIRC).

In case none of that helps, here's a specification that describes how to create a standard UUID: http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt It's not specific to any programming language.

uliwitness
  • 8,532
  • 36
  • 58
1

In LiveCode 6.1 (released today) you can create a uuid using the uuid function. Type 4 random uuid is the default and type 3 and 5 digest based uuids are also implemented.

Monte Goulding
  • 2,380
  • 1
  • 21
  • 25
0

The following function creates a type 4 (random) UUID:

function getUUID
   local tUUIDpattern
   local tUUID
   local tHexDigits
   put "xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx" into tUUIDpattern
   put "1234567890abcdef" into tHexDigits
   repeat for each char tChar in tUUIDpattern
      if tChar = "x" then
         put any char of tHexDigits  after tUUID
      else
         put tChar after tUUID
      end if
   end repeat
   return tUUID
end getUUID
z--
  • 2,186
  • 17
  • 33
0

by now (at least in version 6.6.1) one can use put uuid(random) without shell

if the type is empty or random a version 4 (random) UUID is returned. A cryptographic quality pseudo-random number generator is used to generate the randomness.
If the type is md5 a version 3 UUID is returned.
If the type is sha1 a version 5 UUID is returned.
Tate83
  • 274
  • 1
  • 7
  • 21