last around 2320
This commit is contained in:
20
siliconid.js
Normal file
20
siliconid.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const base62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
function toBase62(num) {
|
||||
let result = "";
|
||||
while (num > 0) {
|
||||
result = base62[num % 62] + result;
|
||||
num = Math.floor(num / 62);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function generateID() {
|
||||
const epochStart = new Date("2020-01-01").getTime();
|
||||
const now = Date.now() - epochStart;
|
||||
const random = Math.floor(Math.random() * 1000); // 3-digit random number
|
||||
const id = now * 1000 + random; // Combine timestamp + randomness
|
||||
return toBase62(id).padStart(8, "0").slice(0, 8); // Ensure 8 chars
|
||||
}
|
||||
|
||||
console.log(generateID()); // Example output: "7zD2LmX1"
|
||||
Reference in New Issue
Block a user