Skip to content

Instantly share code, notes, and snippets.

@davidgrenier
Created June 6, 2014 18:00
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 davidgrenier/0a23c344eb2311c3547d to your computer and use it in GitHub Desktop.
Save davidgrenier/0a23c344eb2311c3547d to your computer and use it in GitHub Desktop.
[<Inline "$v.toString(16)">]
let toHex (v: int) = X<_>
let guid() =
let rx = EcmaScript.RegExp("[xy]", "g")
EcmaScript.String("xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx").Replace(rx, As (fun c ->
let r = EcmaScript.Math.Random() * 16.0 |> int
let v =
match c with
| 'x' -> r
| _ -> r &&& 0x3 ||| 0x8
toHex v
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment