Last active
September 23, 2024 15:12
-
-
Save exceptionpilot/4cc3985627d602017131c2dc741b6c27 to your computer and use it in GitHub Desktop.
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
function generateWeirdUniqueID(length) { | |
const chars = | |
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+=-[]{}|;:,.<>?'; | |
const replacements = { | |
w: ['w', 'W', 'vv'], | |
e: ['e', '3', '€'], | |
i: ['i', '1', '!', '|'], | |
r: ['r', 'R', '®'], | |
d: ['d', 'D'], | |
}; | |
let weird = 'weird'; | |
let modifiedWeird = ''; | |
// Randomly replace characters in "weird" | |
for (const char of weird) { | |
const options = replacements[char] || [char]; | |
modifiedWeird += options[Math.floor(Math.random() * options.length)]; | |
} | |
// Generate random characters to fill the ID | |
let id = ''; | |
for (let i = 0; i < length - modifiedWeird.length; i++) { | |
id += chars.charAt(Math.floor(Math.random() * chars.length)); | |
} | |
// Insert the modified "weird" at a random position | |
const weirdPosition = Math.floor(Math.random() * (id.length + 1)); | |
id = id.split(''); | |
id.splice(weirdPosition, 0, modifiedWeird); | |
id = id.join(''); | |
// Append a unique component like a timestamp for uniqueness | |
id += Date.now().toString(36); // Use base36 for shorter timestamp | |
return id; | |
} | |
// Example usage: | |
// const weirdUniqueID = generateWeirdUniqueID(16); // Generate a 16-character ID | |
// console.log(weirdUniqueID); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment