Skip to content

Instantly share code, notes, and snippets.

@jonypawks
Created October 28, 2013 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonypawks/7192173 to your computer and use it in GitHub Desktop.
Save jonypawks/7192173 to your computer and use it in GitHub Desktop.
Coffeescript UUID4
_random =
if crypto?.getRandomValues
-> crypto.getRandomValues(new Uint32Array(1))[0] / Math.pow(2, 32)
else
Math.random
uuid4 = ->
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace /[xy]/g, (c) ->
u = _random() * 16 | 0
u = u & 0x3 | 0x8 if c is 'y'
u.toString 16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment