Version 5 of GUID and UUID

Updated 2004-02-11 00:56:53

UUIDs (Universally Unique Identifier) or GUIDs (Globally Unique Identifier) are defined in this document: [L1 ]

Windows provides an API for generating GUIDs and some extensions make use of this, but I needed a pure-Tcl UUID generator. So, I came up with this. This proc, by no means, conforms to the standards discussed in the above document, but it does produce unique identifiers that are good enough for me. :) Damon Courtney

 proc uuid {} {
     ## Try and get a string unique to this host.
     set str [info hostname]$::tcl_platform(machine)$::tcl_platform(os)
     binary scan $str h* hex

     set    uuid [format %2.2x [clock seconds]]
     append uuid -[string range [format %2.2x [clock clicks]] 0 3]
     append uuid -[string range [format %2.2x [clock clicks]] 2 5]
     append uuid -[string range [format %2.2x [clock clicks]] 4 end]
     append uuid -[string range $hex 0 11]

     return $uuid
 }

 proc guid {} {
     ## Return a GUID for Windows, which is just an uppercase UUID with brackets.
     return \{[string toupper [uuid]]\}
 }