Last active
December 16, 2015 15:09
-
-
Save pbojinov/5453782 to your computer and use it in GitHub Desktop.
Tokenizer
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
String.prototype.shuffle = function(size) { | |
var arr = this.split(''); | |
for (var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x){}; | |
arr = arr.join(''); | |
return size ? arr.substr(0, Math.min(size, arr.length-1)) : arr; | |
}; | |
var Tokenizer = { | |
seed: '1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm', | |
getToken: function(size) { | |
size = size || 10; | |
var today = new Date().getTime(); | |
return (Tokenizer.seed + today).shuffle(size); | |
} | |
}; | |
Tokenizer.getToken(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
window.Tokenizer = window.Tokenizer || {};
Tokenizer.generate = function(size){
var seed = '1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm'.split('');
for (var j, x, i = seed.length; i; j = parseInt(Math.random() * i), x = seed[--i], seed[i] = seed[j], seed[j] = x){};
return seed.slice(0, Math.min(size, seed.length)).join('');
};
window.myProject = {
myToken: Tokenizer.generate(10);
};