Skip to content

Instantly share code, notes, and snippets.

@SatoshiMota
Created October 11, 2025 12:22
Show Gist options
  • Save SatoshiMota/277fa3490fee63657a460af6378eaa55 to your computer and use it in GitHub Desktop.
Save SatoshiMota/277fa3490fee63657a460af6378eaa55 to your computer and use it in GitHub Desktop.
Phonetic Username Generator
function generateNick(minLength = 6, maxLength = 15, symbols = "-_", useСapitalLetters = true) {
while (true) {
let word = "";
// Генерация начального слова (по умолчанию согласная и после неё гласная), 70% шанс что первая буква согласная, 3% щанс что тип буквы повторится подрят
let isConsonant = Math.random() < 0.7;
const wordLength = Math.floor(Math.random() * (maxLength - minLength + 1)) + minLength;
for (let i = 0; i < wordLength; i++) {
const pool = isConsonant ? "bcdfghjklmnpqrstvwxyz" : "aeiou";
word += pool[Math.floor(Math.random() * pool.length)];
if (Math.random() >= 0.03) {
isConsonant = !isConsonant;
}
}
// 10% шанс добавить число от 0 до 999 в конец
if (Math.random() < 0.1) {
let number = Math.floor(Math.random() * 10001);
// 5% шанс добавить один из знаков перед цыфрами (если в функцию передали символы)
if (symbols.length > 0 && Math.random() < 0.05) {
const symbol = symbols[Math.floor(Math.random() * symbols.length)];
number = symbol + number;
}
word = word + number;
}
// 3% шанс добавить число от 1000 до 10000 в конец
else if (Math.random() < 0.03) {
let number = Math.floor(Math.random() * (10000 - 1000 + 1)) + 1000;
// 5% шанс добавить один из знаков перед цыфрами (если в функцию передали символы)
if (symbols.length > 0 && Math.random() < 0.05) {
const symbol = symbols[Math.floor(Math.random() * symbols.length)];
number = symbol + number;
}
word = word + number;
}
// 5% шанс добавить число от 1950 до 2025 в конец
else if (Math.random() < 0.05) {
let number = Math.floor(Math.random() * (2025 - 1950 + 1)) + 1950;
// 5% шанс добавить один из знаков перед цыфрами (если в функцию передали символы)
if (symbols.length > 0 && Math.random() < 0.05) {
const symbol = symbols[Math.floor(Math.random() * symbols.length)];
number = symbol + number;
}
word = word + number;
}
// 10% шанс добавить префикс в конец с символом перед словом (если в функцию передали символы)
else if (Math.random() < 0.10) {
const suffixes = [
'xyz', 'tv', 'hd', 'v2', 'v3', '999', '000', '666',
'777', 'god', 'pro', 'dev', 'bot', 'lol', 'noob', 'gg',
'no', 'ez', 'dark', 'aim', 'afk', 'rip', 'rep', 'ultra',
'run', 'win', 'top', '1337', 'max', 'low', 'off', 'dad',
'hub', 'dog', 'cat', 'pig', 'fox', 'live', 'root', 'gay',
'bro', 'end', 'war', 'wiz', 'gun', 'dead', 'kill', 'rush',
'ua', 'usa', 'eu', 'ru', 'jp', 'br', 'cn', 'kr', 'solo', 'zero'
];
const suffix = suffixes[Math.floor(Math.random() * suffixes.length)];
// 15% шанс добавить один из знаков перед префиксом (если в функцию передали символы)
let sep
if (symbols.length > 0 && Math.random() < 0.15) {
sep = symbols[Math.floor(Math.random() * symbols.length)];
} else {
sep = '';
}
word = word + sep + suffix;
}
// 8% шанс добавить 1 из знаков в любое место кроме начала и конца (если в функцию передали символы)
if (symbols.length > 0 && Math.random() < 0.08) {
if (word.length <= 3) return;
const symbol = symbols[Math.floor(Math.random() * symbols.length)];
const pos = Math.floor(Math.random() * (word.length - 2)) + 1;
word = word.slice(0, pos) + symbol + word.slice(pos);
};
// Если в функцию передали использовать большие символы
if (useСapitalLetters) {
// 3% шанс сделать всё слово заглавными
if (Math.random() < 0.03) {
word = word.toUpperCase();
}
// 2% шанс сделать пол слова (начало или конец) заглавными
else if (Math.random() < 0.03 && word.length > 1) {
const mid = Math.floor(word.length / 2);
if (Math.random() < 0.5) {
word = word.slice(0, mid).toUpperCase() + word.slice(mid);
} else {
word = word.slice(0, mid) + word.slice(mid).toUpperCase();
}
}
// 1% шанс сделать каждую 2 букву заглавной
else if (Math.random() < 0.01 && word.length > 1) {
let transformed = '';
for (let i = 0; i < word.length; i++) {
transformed += (i % 2 === 1) ? word[i].toUpperCase() : word[i];
}
word = transformed;
} else {
// 15% шанс сделать 1 букву заглавной
if (Math.random() < 0.15) {
word = word.charAt(0).toUpperCase() + word.slice(1);
}
// 10% шанс сделать любую букву заглавной кроме первой
if (Math.random() < 0.10 && word.length > 1) {
const index = Math.floor(Math.random() * (word.length - 1)) + 1;
const char = word[index].toUpperCase();
let prefix = '';
// 5% шанс добавить один из знаков перед большой буквой (если в функцию передали символы)
if (symbols.length > 0 && Math.random() < 0.05) {
prefix = symbols[Math.floor(Math.random() * symbols.length)];
}
word = word.slice(0, index) + prefix + char + word.slice(index + 1);
}
}
}
// 13% шанс заменить одну случайную букву o на 0
if (Math.random() < 0.13 && word.includes('o')) {
const oIndices = [...word.matchAll(/o/g)].map(match => match.index);
if (oIndices.length > 0) {
const randomIndex = oIndices[Math.floor(Math.random() * oIndices.length)];
word = word.slice(0, randomIndex) + '0' + word.slice(randomIndex + 1);
}
}
// 13% шанс заменить одну случайную букву g на 9
if (Math.random() < 0.13 && word.includes('g')) {
const gIndices = [...word.matchAll(/g/g)].map(match => match.index);
if (gIndices.length > 0) {
const randomIndex = gIndices[Math.floor(Math.random() * gIndices.length)];
word = word.slice(0, randomIndex) + '9' + word.slice(randomIndex + 1);
}
}
// 13% шанс заменить одну случайную букву l на 1
if (Math.random() < 0.13 && word.includes('l')) {
const oIndices = [...word.matchAll(/l/g)].map(match => match.index);
if (oIndices.length > 0) {
const randomIndex = oIndices[Math.floor(Math.random() * oIndices.length)];
word = word.slice(0, randomIndex) + '1' + word.slice(randomIndex + 1);
}
}
// 28% шанс заменить фразу for на 4
if (Math.random() < 0.28 && word.includes('for')) {
word = word.replace(/for/g, '4');
}
// 5% шанс удалить случайную букву
if (Math.random() < 0.05 && word.length > maxLength) {
const delIndex = Math.floor(Math.random() * word.length);
word = word.slice(0, delIndex) + word.slice(delIndex + 1);
}
// 5% шанс продублировать случайную букву
if (Math.random() < 0.05 && word.length > 0) {
const dupIndex = Math.floor(Math.random() * word.length);
word = word.slice(0, dupIndex) + word[dupIndex] + word.slice(dupIndex);
}
// Если длина не соответствует перезапуск
if (word.length < minLength && word.length > maxLength) {
continue;
} else {
return word;
}
}
}
console.log("\nДлинна от 6 до 13 символов, без знаков, без больших букв");
for (let i = 0; i < 10; i++) {
// Длинна от 6 до 13 символов, без знаков, без больших букв
const username = generateNick(6, 13, "", false);
console.log(username);
}
console.log("\n\nДлинна от 6 до 13 символов, со знаками -_ без больших букв");
for (let i = 0; i < 10; i++) {
// Длинна от 6 до 13 символов, без знаков, без больших букв
const username = generateNick(6, 13, "-_", false);
console.log(username);
}
console.log("\n\nДлинна от 6 до 13 символов, со знаками -_ с большими буквами");
for (let i = 0; i < 10; i++) {
// Длинна от 6 до 13 символов, со знаками -_ с большими буквами
const username = generateNick(6, 13, "-_", true);
console.log(username);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment