I want to create a random string (token) which can be used to identify a user whilst avoiding any potential conflicts with any other users\' tokens.
What I was thinking
You could generate a random number and convert it to base 36 (0-9a-z):
0-9a-z
var rand = function() { return Math.random().toString(36).substr(2); // remove `0.` }; var token = function() { return rand() + rand(); // to make it longer }; token(); // "bnh5yzdirjinqaorq0ox1tf383nb3xr"