-
-
Save ticking-clock/6391747 to your computer and use it in GitHub Desktop.
CoffeeScript UUID (guid) function
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
# RFC1422-compliant CoffeeScript UUID function. | |
# Generates a UUID from a random number, which means it is not entirely unique. | |
# See: http://stackoverflow.com/questions/105034 | |
guid = -> | |
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace /[xy]/g, (c) -> | |
r = Math.random() * 16 | 0 | |
v = if c is 'x' then r else (r & 0x3|0x8) | |
v.toString(16) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment