Skip to content

Instantly share code, notes, and snippets.

@dr-dimitru
Forked from RavisMsk/gist:b6f67036c4782981c5f1
Last active August 29, 2015 14:08
Show Gist options
  • Save dr-dimitru/8aa4ffb30a53d787e79e to your computer and use it in GitHub Desktop.
Save dr-dimitru/8aa4ffb30a53d787e79e to your computer and use it in GitHub Desktop.
var symbols = '23456789QWERTYUPASDFGHJKZXCVBNM';
var qty = 1500000;
var length = 7;
var code, hash, i, maxIndex, rand, symbol, _i, _j;
maxIndex = symbols.length - 1;
for (i = _i = 1; 1 <= qty ? _i <= qty : _i >= qty; i = 1 <= qty ? ++_i : --_i) {
code = 'KX ';
hash = 0;
for (symbol = _j = 1; 1 <= length ? _j <= length : _j >= length; symbol = 1 <= length ? ++_j : --_j) {
rand = Math.floor((Math.random() * maxIndex) + 1);
code += symbols[rand];
hash += rand;
if (hash > maxIndex) {
hash = hash - maxIndex;
}
}
code += symbols[hash];
db.codes.insert({
code: code,
hash: symbols[hash]
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment