Created
October 27, 2016 18:09
-
-
Save danesparza/fdf989d820c22f3cd589eea7885fb368 to your computer and use it in GitHub Desktop.
A pseudorandom UUID implementation using Go's crypto/rand
This file contains hidden or 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" | |
"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