Created
July 10, 2018 18:08
-
-
Save linux4life798/1dcc9181518e10a3fcc35c81e45a42b2 to your computer and use it in GitHub Desktop.
Function to generate a random MQTT client ID with a common prefix
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
import CRAND "crypto/rand" | |
// GenMQTTClientID generates a random client id for mqtt | |
func GenMQTTClientID(prefix string) (string, error) { | |
r, err := CRAND.Int(CRAND.Reader, new(big.Int).SetInt64(100000)) | |
if err != nil { | |
return "", fmt.Errorf("Failed to generate MQTT client ID: %v", err) | |
} | |
return prefix + r.String(), nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment