Skip to content

Instantly share code, notes, and snippets.

@JulianDicken
Created July 16, 2021 11:31
Show Gist options
  • Save JulianDicken/cf249f514a22d3b67fbd5678a4d386c5 to your computer and use it in GitHub Desktop.
Save JulianDicken/cf249f514a22d3b67fbd5678a4d386c5 to your computer and use it in GitHub Desktop.
A UUID4 String Generator for GML
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