Created
February 23, 2012 16:03
-
-
Save bmc/1893440 to your computer and use it in GitHub Desktop.
Generate UUID, using Math.random(), in CoffeeScript
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
# RFC1422-compliant Javascript UUID function. Generates a UUID from a random | |
# number (which means it might not be entirely unique, though it should be | |
# good enough for many uses). See http://stackoverflow.com/questions/105034 | |
uuid = -> | |
'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