DEV Community

Discussion on: Randomness with JavaScript

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

I actually use Math.random().toString(36).substr(2) quite often, when I don't want to name things.

But when I want to ensure no collision, I generally use nanoid or uuid/v4. shortid is nice, but may have more collisions than nanoid, as well as slower to generate. (Actually, I read that some parts of the code between shortid and nanoid are shared.)

Collapse
 
ksankar profile image
Kailash Sankar

Thanks for the input! Updated post to link nanoid.
Yeah, looks like it's published by the same folks and shortId has a dependency on nanoid.