-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathuuid.brs
30 lines (26 loc) · 923 Bytes
/
uuid.brs
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
' Generates uuid in a naive way.
' The purpose of the function is to generate identifiers faster then native brightscript uuid generator.
' It is intended to be used internaly for i.e. component ids on a small scale as it relies on pseudo random number generator.
' For other purposes use ifDeviceInfo.GetRandomUUID.
' Parts length: 8-4-4-4-12
' @example fnwijen2-n51i-jni1-5jd5-1234jjkjnfe2
' @returns {String}
function uuid() as String
parts = [
_uuidGetRandomHexString(8),
_uuidGetRandomHexString(4),
_uuidGetRandomHexString(4),
_uuidGetRandomHexString(4),
_uuidGetRandomHexString(12),
]
return parts.join("-")
end function
function _uuidGetRandomHexString(length as Integer) as String
hexChars = "0123456789ABCDEF"
hexCharsNumber = Len(hexChars)
hexString = ""
for i = 1 to length
hexString += hexChars.mid(Rnd(hexCharsNumber) - 1, 1)
end for
return hexString
end function