Skip to content

Instantly share code, notes, and snippets.

@stresler
Created April 17, 2015 16:04
Show Gist options
  • Save stresler/e28bfa894640c393a690 to your computer and use it in GitHub Desktop.
Save stresler/e28bfa894640c393a690 to your computer and use it in GitHub Desktop.
Go Function to generate a random MAC address.
func GenerateMac() (net.HardwareAddr) {
buf := make([]byte, 6)
var mac net.HardwareAddr
_, err := rand.Read(buf)
if err != nil {}
// Set the local bit
buf[0] |= 2
mac = append(mac, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5])
return mac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment