Last active
August 29, 2015 14:02
-
-
Save hagiyat/f12bf8e993ebcbd5e3aa to your computer and use it in GitHub Desktop.
generate random word
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(length) { | |
var range = function(start, end) { | |
var result = []; | |
for(var i=start; i<=end; i++) { | |
result.push(i); | |
} | |
return result; | |
}; | |
var source = (function(src, count) { | |
var i = src.length; | |
while(i) { | |
var j = Math.floor(Math.random() * i); | |
var t = src[--i]; | |
src[i] = src[j]; | |
src[j] = t; | |
} | |
return src.slice(0, count); | |
// a-zA-Z0-9 | |
} ([].concat(range(48, 57), range(97, 122), range(65, 90)), length)); | |
return String.fromCharCode.apply(String, source); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment