CristhGunners - Desarrollador de Software

Cristhofer Andana

Desarrollador de Software

Generar random UUID en Javascript

js

julio 30, 2024

Generar random UUID en Javascript:

const generateRandomUUID = (a) =>
  a
    ? (a ^ ((Math.random() * 16) >> (a / 4))).toString(16)
    : ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(
        /[018]/g,
        generateRandomUUID
      );

console.log(generateRandomUUID()); // 8935bb0d-6503-441f-bb25-7bc685b5b5bc
console.log(generateRandomUUID()); // f138f635-acbd-4f78-9be5-ca3198c4cf34