Created
January 30, 2016 23:49
-
-
Save asim/8799b4e7233c880098f6 to your computer and use it in GitHub Desktop.
UUID gen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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