Skip to content

Instantly share code, notes, and snippets.

@danesparza
Created October 27, 2016 18:09
Show Gist options
  • Save danesparza/fdf989d820c22f3cd589eea7885fb368 to your computer and use it in GitHub Desktop.
Save danesparza/fdf989d820c22f3cd589eea7885fb368 to your computer and use it in GitHub Desktop.
A pseudorandom UUID implementation using Go's crypto/rand
package main
import (
"crypto/rand"
"fmt"
)
func main() {
b := make([]byte, 16)
_, err := rand.Read(b)
if err != nil {
fmt.Println("Error: ", err)
return
}
uuid := fmt.Sprintf("%X-%X-%X-%X-%X", b[0:4], b[4:6], b[6:8], b[8:10], b[10:])
fmt.Printf("The UUID: %v", uuid)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment