Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

220
Views
Need help understanding how this JS code is generating UUID

I got this piece of code for generating UUID in case the browser doesn't support crypto.randomUUID.

I need help understanding how this works. A step by step process would be much appreciated. Would also like to know the official term that is used to define this kind of process.

var random_string = (
    Math.random().toString(16) +
    Math.random().toString(16) +
    Math.random().toString(16) +
    Math.random().toString(16) +
    Math.random().toString(16)
  ).replace(/0\./g, ""),
  random_y_bit = [8, 9, "a", "b"][~~(Math.random() * 4)],
  template_uuid = /.*(........)..(....)..(...)..(...)..(............).*/,
  replace_pattern = "$1-$2-4$3-" + random_y_bit + "$4-$5";

return random_string.replace(template_uuid, replace_pattern);
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!