I want a 5 character string composed of characters picked randomly from the set [a-zA-Z0-9].
What\'s the best way to do this with JavaScript?
Here are some easy one liners. Change new Array(5) to set the length.
0-9a-znew Array(5).join().replace(/(.|$)/g, function(){return ((Math.random()*36)|0).toString(36);})
0-9a-zA-Znew Array(5).join().replace(/(.|$)/g, function(){return ((Math.random()*36)|0).toString(36)[Math.random()<.5?"toString":"toUpperCase"]();});