1var characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
2var result = ""
3var charactersLength = characters.length;
4
5for ( var i = 0; i < 5 ; i++ ) {
6 result += characters.charAt(Math.floor(Math.random() * charactersLength));
7}
8
9console.log(result)
1// n is an integer
2function randomString (n) {
3 // create array of length n filled with null
4 let tmpArr = Array.apply(null, Array(n));
5
6 // for each index generate a random positive integer
7 // less than 36 and convert it to a base 36 digit
8 tmpArr.map((v, i) =>
9 Math.floor(Math.random() * 36).toString(36)
10 ).join('');
11
12 return tmpArr;
13}