Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

I'm trying to create globally-unique identifiers in JavaScript. I'm not sure what routines are available on all browsers, how "random" and seeded the built-in random number generator is, etc..

The GUID / UUID should be at least 32 characters and should stay in the ASCII range to avoid trouble when passing them around.

1 Answer

0 votes
by (106k points)

For creating GUID / UUID in JavaScript you can use the following code:-

function uuidv4() { 

return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { 

var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); 

return v.toString(16); 

   }); 

console.log(uuidv4())

Related questions

0 votes
1 answer
asked Jul 30, 2019 in Java by Krishna (2.6k points)
0 votes
1 answer
asked Jul 2, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...