Created
July 16, 2021 11:31
-
-
Save JulianDicken/cf249f514a22d3b67fbd5678a4d386c5 to your computer and use it in GitHub Desktop.
A UUID4 String Generator for GML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function generate_uuid4_string() { | |
//As per https://www.cryptosys.net/pki/uuid-rfc4122.html | |
//FIXME - Do this without random()/choose() calls | |
var _UUID = sha1_string_utf8(string(current_time) + string(date_current_datetime()) + string(random(0xFFFFFF))); | |
_UUID = string_set_byte_at(_UUID, 9, 0x2D) | |
_UUID = string_set_byte_at(_UUID, 14, 0x2D) | |
_UUID = string_set_byte_at(_UUID, 19, 0x2D) | |
_UUID = string_set_byte_at(_UUID, 24, 0x2D) | |
_UUID = string_delete(_UUID, 37, 4) | |
_UUID = string_upper(_UUID) | |
_UUID = string_set_byte_at(_UUID, 15, 0x34); | |
_UUID = string_set_byte_at(_UUID, 20, choose(0x38, 0x39, 0x41, 0x42)); | |
return _UUID; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment