在Livecode(或HyperTalk)中如何创建UUID(GUID)?

3
4个回答

3

如果你使用类Unix操作系统(如Linux或MacOS),你可以使用shell()函数调用uuidgen终端命令。具体操作如下:

put shell("uuidgen") into theUUID

这有点过度,它创建了一个shell,在其中运行一个命令行应用程序,然后再退出。但是它可以在旧版LiveCode上工作,并且与shell脚本的操作方式并没有太大区别。

在HyperCard中,您必须使用AppleScript,可以在其脚本设置为AppleScript的对象中使用,或者使用“do X as AppleScript”命令。不确定AppleScript是否可以本地构建UUID,但如果不能,则可以使用AppleScript运行shell脚本。(在HyperCard中不存在shell()函数,我IRC发明了SuperCard)。

如果所有这些都无法帮助您,这里有一份规范,描述如何创建标准UUID:http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt,它不特定于任何编程语言。


1
在LiveCode 6.1(今天发布)中,您可以使用uuid函数创建uuid。默认情况下是类型4随机uuid,同时也实现了基于类型3和5摘要的uuid。

0

目前(至少在版本6.6.1中),可以使用put uuid(random)而无需使用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.

Monte Goulding之前已经给出了相同的答案。 - z--

0
以下函数创建一个类型为4(随机)的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

任何字符都不是密码学质量的随机性。 - Monte Goulding
“any” 不具备密码学质量如何影响汉尼斯脚本的有效性? - Mark

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接