Created
August 29, 2019 22:39
-
-
Save alexpilugin/9bd5085c7e5b05e4e7fdfa3256d7cf9f 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
function getNumberId(prefix) { | |
var p = prefix || "i"; | |
function shuffle(str) { | |
var a = str.split(""); | |
var n = a.length; | |
for (var i = n - 1; i > 0; i--) { | |
var j = Math.floor(Math.random() * (i + 1)); | |
var tmp = a[i]; | |
a[i] = a[j]; | |
a[j] = tmp; | |
} | |
return a.join(""); | |
} | |
var str = new Date().getTime() + (Math.random() * 999 + 1000).toFixed() //string | |
return p+shuffle(str) | |
} |
Author
alexpilugin
commented
Aug 29, 2019
•
function getUniqueID(prefix, length) {
var p = prefix || "i";
var len = length || 10;
function shuffle(str) {
var a = str.split("");
var n = a.length;
for (var i = n - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
return a.join("");
}
var str = new Date().getTime() + (Math.random() * 999 + 1000).toFixed() //string
var n = Number.parseInt(shuffle(str));
return (p + n.toString(36)).substring(0, len)
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment