Created
January 23, 2012 19:47
-
-
Save findzen/1665188 to your computer and use it in GitHub Desktop.
hash generator
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
| var hash = function(s){ | |
| var n; | |
| if (typeof(s) == 'number' && s === parseInt(s, 10)){ | |
| s = Array(s + 1).join('x'); | |
| } | |
| return s.replace(/x/g, function(){ | |
| var n = Math.round(Math.random() * 61) + 48; | |
| n = n > 57 ? (n + 7 > 90 ? n + 13 : n + 7) : n; | |
| return String.fromCharCode(n); | |
| }); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Function generates random stirng containing characters: 0-9a-zA-Z.
Function takes one argument which may be Integer or String.
If argument is Integer then argument defines length of generated string.
If argument is String then given string is returned but all 'x' characters are replaced with random characters.
== Hash based on date - fast way ==
If you want hash based on date you may just use
source: http://mynthon.net/howto/-/webdev/javascript-random-hash-generator.txt