/** * @title: Random-alphanumeric-strings * @author: Shahzad Nawaz * @dated: 7/16/2015. */ //e.g #1 var sixLenstrings = getRandomStrings(6, 2); console.log(sixLenstrings); // output: ["UlTl14", "JZRbSS"] //e.g #2 var threeLenstrings = getRandomStrings(3, 7); console.log(threeLenstrings); // output: ["gE3", "fO1", "AZT", "W37", "ntA", "E9Q", "hzG"] //function that returns strings array. function getRandomStrings(stringLen, totalStrings) { var item, items, possible; //possible characters to include in creating random strings - alpha-numeric possible = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; items = []; for (var i = 0; i < totalStrings; i++) { item = ""; for (var c = 0; c < stringLen; c++) { item += possible.charAt(Math.floor(Math.random() * possible.length)); } items.push(item); } return items; }