Try this, what i use every time :
function myFunction() {_x000D_
var hash = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012346789";_x000D_
var random8 = '';_x000D_
for(var i = 0; i < 5; i++){_x000D_
random8 += hash[parseInt(Math.random()*hash.length)];_x000D_
}_x000D_
console.log(random8);_x000D_
document.getElementById("demo").innerHTML = "Your 5 character string ===> "+random8;_x000D_
} _x000D_
_x000D_
<!DOCTYPE html>_x000D_
<html>_x000D_
<body>_x000D_
_x000D_
<p>Click the button to genarate 5 character random string .</p>_x000D_
_x000D_
<button onclick="myFunction()">Click me</button>_x000D_
_x000D_
<p id="demo"></p>_x000D_
_x000D_
_x000D_
_x000D_
</body>_x000D_
</html>
_x000D_