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?
let r = Math.random().toString(36).substring(7);
console.log("random", r);
Note: The above algorithm has the following weaknesses:
Math.random()
may produce predictable ("random-looking" but not really random) output depending on the implementation. The resulting string is not suitable when you need to guarantee uniqueness or unpredictability.