forked from Paris/AutoHotkey-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
uuid.ahk
35 lines (32 loc) · 1004 Bytes
/
uuid.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
Function: uuid
Generates a time-based UUID string <http://en.wikipedia.org/wiki/UUID>.
Parameters:
c - (optional) true to use your computers MAC code (default: false)
Returns:
A UUID string.
About: License
- Version 1.1 <http://www.autohotkey.net/~polyethene/#uuid>
- Dedicated to the public domain (CC0 1.0) <http://creativecommons.org/publicdomain/zero/1.0/>
*/
uuid(c = false) {
static n = 0, l, i
f := A_FormatInteger, t := A_Now, s := "-"
SetFormat, Integer, H
t -= 1970, s
t := (t . A_MSec) * 10000 + 122192928000000000
If !i and c {
Loop, HKLM, System\MountedDevices
If i := A_LoopRegName
Break
StringGetPos, c, i, %s%, R2
StringMid, i, i, c + 2, 17
} Else {
Random, x, 0x100, 0xfff
Random, y, 0x10000, 0xfffff
Random, z, 0x100000, 0xffffff
x := 9 . SubStr(x, 3) . s . 1 . SubStr(y, 3). SubStr(z, 3)
} t += n += l = A_Now, l := A_Now
SetFormat, Integer, %f%
Return, SubStr(t, 10) . s . SubStr(t, 6, 4) . s . 1 . SubStr(t, 3, 3) . s . (c ? i : x)
}