Skip to content

Instantly share code, notes, and snippets.

@murphysean
Created October 21, 2015 21:40
Show Gist options
  • Save murphysean/4d4ea38452d29f90501c to your computer and use it in GitHub Desktop.
Save murphysean/4d4ea38452d29f90501c to your computer and use it in GitHub Desktop.
Create a v4 UUID in go
package main
import(
"crypto/rand"
)
func GenUUIDv4() string {
u := make([]byte, 16)
rand.Read(u)
//Set the version to 4
u[6] = (u[6] | 0x40) & 0x4F
u[8] = (u[8] | 0x80) & 0xBF
return fmt.Sprintf("%x-%x-%x-%x-%x", u[0:4], u[4:6], u[6:8], u[8:10], u[10:])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment