Created
April 3, 2016 05:20
-
-
Save ciscoheat/4b1797fa56648adac163f44186f1823a to your computer and use it in GitHub Desktop.
Quick UUID generator in Haxe
This file contains hidden or 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
class UUID { | |
public static function uuid() { | |
// Based on https://gist.github.com/LeverOne/1308368 | |
var uid = new StringBuf(), a = 8; | |
uid.add(StringTools.hex(Std.int(Date.now().getTime()), 8)); | |
while((a++) < 36) { | |
uid.add(a*51 & 52 != 0 | |
? StringTools.hex(a^15 != 0 ? 8^Std.int(Math.random() * (a^20 != 0 ? 16 : 4)) : 4) | |
: "-" | |
); | |
} | |
return uid.toString().toLowerCase(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Date.now().getTime()
does not fit in the space of a 32 bit integer and causes an overflow condition.