Skip to content

Instantly share code, notes, and snippets.

@yuanchuan
Created December 15, 2010 01:48
Show Gist options
  • Save yuanchuan/741512 to your computer and use it in GitHub Desktop.
Save yuanchuan/741512 to your computer and use it in GitHub Desktop.
/**
* Get random charactor from a given charset
*/
var getRandomChar = (function(str) {
var len = str.length;
return function() {
return str.charAt(Math.floor(Math.random() * len));
};
}(String.fromCharCode.apply(null, (function() {
var buffer = [], start = 12449, limit = 12531;
while (
(start < limit) && buffer.push(start++)
);
return buffer;
}()))));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment