Skip to content

Instantly share code, notes, and snippets.

@asim
Created January 30, 2016 23:49
Show Gist options
  • Save asim/8799b4e7233c880098f6 to your computer and use it in GitHub Desktop.
Save asim/8799b4e7233c880098f6 to your computer and use it in GitHub Desktop.
UUID gen
package main
import (
"crypto/rand"
"encoding/hex"
"fmt"
)
func newUUID() string {
uuid := make([]byte, 16)
n, err := rand.Read(uuid)
if n != len(uuid) || err != nil {
return "unknown"
}
uuid[8] = 0x80
uuid[4] = 0x40
return hex.EncodeToString(uuid)
}
func main() {
fmt.Println(newUUID())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment