Skip to content

Instantly share code, notes, and snippets.

@ticking-clock
Created August 30, 2013 16:34
Show Gist options
  • Save ticking-clock/6391747 to your computer and use it in GitHub Desktop.
Save ticking-clock/6391747 to your computer and use it in GitHub Desktop.
CoffeeScript UUID (guid) function
# 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