I have a script that, when a user loads, creates a unique id. Which is then saved in localStorage
and used for tracking transactions. Sort of like using a cookie, except since the browser is generating the unique id there might be collisions when sent to the server. Right now I'm using the following code:
function genID() {
return Math.random().toString(36).substr(2)
+ Math.random().toString(36).substr(2)
+ Math.random().toString(36).substr(2)
+ Math.random().toString(36).substr(2);
}
I realize this is a super basic implementation, and want some feedback on better ways to create a "more random" id that will prevent collisions on the server. Any ideas?