Skip to content

Instantly share code, notes, and snippets.

@makeding
Created February 28, 2023 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makeding/9c07f5150601bbb2dec3795d9a373c71 to your computer and use it in GitHub Desktop.
Save makeding/9c07f5150601bbb2dec3795d9a373c71 to your computer and use it in GitHub Desktop.
export const generateRandomMac = (/* prefix = '' */) => {
// https://stackoverflow.com/questions/24621721/how-would-one-generate-a-mac-address-in-javascript
// https://en.wikipedia.org/wiki/MAC_address#Ranges_of_group_and_locally_administered_addresses
return 'XR:XX:XX:XX:XX:XX'.replace(/X/ig, (x) => {
return "0123456789ABCDEF"[Math.floor(Math.random() * 16)]
}).replace('R', '26AE'[Math.floor(Math.random() * 4)])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment