Created
February 3, 2014 05:12
-
-
Save MaximOrlovsky/8779159 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /** | |
| * Generate MD5-like string. | |
| * @author MaximOrlovsky github.com | |
| * @example stringLikeMd5.generate(16); //return 16 characters of md5-like string | |
| * @type {{allowedSigns: string, generate: generate, getRandomSign: getRandomSign}} | |
| */ | |
| var stringLikeMd5 = { | |
| allowedSigns: 'abcdef1234567890', | |
| generate: function (limit) { | |
| var limit = limit || 32, | |
| alowedLength = this.allowedSigns.length, | |
| str = ''; | |
| for ( i=0; i<limit; i++ ) { | |
| str += '' + this.getRandomSign(); | |
| } | |
| return str; | |
| }, | |
| getRandomSign: function () { | |
| var max = this.allowedSigns.length, | |
| min = 1; | |
| var rand = Math.floor(Math.random() * (max - min + 1) + min); | |
| return this.allowedSigns[rand]; | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment