Last active
August 29, 2015 14:27
-
-
Save xafarali/515c561b96c9f30b5972 to your computer and use it in GitHub Desktop.
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
// 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