Skip to content

Instantly share code, notes, and snippets.

@xafarali
Last active August 29, 2015 14:27
Show Gist options
  • Save xafarali/515c561b96c9f30b5972 to your computer and use it in GitHub Desktop.
Save xafarali/515c561b96c9f30b5972 to your computer and use it in GitHub Desktop.
// Random Generator
function gen_rand(length, type ) {
var mode = type || 0;
/*
* @length , Length of Random output
* @type , Mode of Random Generator
0 = mixed string mode
1 = digits
2 = string
*/
var len = length || 5;
var text = "";
var char_digit = "0123456789";
var char_text = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~!@#$%^&";
if ( mode == 0 || mode == "default" ) {
var possible = char_digit + char_text;
} else if (mode == 1 || mode == "digit") {
possible = char_digit;
} else {
possible = char_text;
}
for( var i=0; i < len; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment