Skip to content

Instantly share code, notes, and snippets.

@exceptionpilot
Last active September 23, 2024 15:12
Show Gist options
  • Save exceptionpilot/4cc3985627d602017131c2dc741b6c27 to your computer and use it in GitHub Desktop.
Save exceptionpilot/4cc3985627d602017131c2dc741b6c27 to your computer and use it in GitHub Desktop.
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