Skip to content

Instantly share code, notes, and snippets.

@ciscoheat
Created April 3, 2016 05:20
Show Gist options
  • Save ciscoheat/4b1797fa56648adac163f44186f1823a to your computer and use it in GitHub Desktop.
Save ciscoheat/4b1797fa56648adac163f44186f1823a to your computer and use it in GitHub Desktop.
Quick UUID generator in Haxe
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();
}
}
@pilotgeraldb
Copy link

Date.now().getTime() does not fit in the space of a 32 bit integer and causes an overflow condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment