VirtWeb/virtweb_frontend/src/utils/RandUtils.ts

12 lines
292 B
TypeScript

/**
* Generate a random MAC address
*/
export function randomMacAddress(prefix: string | undefined): string {
let mac = "XX:XX:XX:XX:XX:XX";
mac = prefix + mac.slice(prefix?.length);
return mac.replace(/X/g, () =>
"0123456789abcdef".charAt(Math.floor(Math.random() * 16))
);
}