VirtWeb/virtweb_frontend/src/utils/RandUtils.ts

12 lines
292 B
TypeScript
Raw Normal View History

2023-12-19 12:26:56 +00:00
/**
* 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))
);
}