I find a mistake.
At least I think it is.
/* Changes include adding `accents` and the `ñ`. I also added `min` and `max` as parameters. */ const accents = 'áéíóú', chars = 'abcdefghijklmnopqrstuvwxyz', a = 'bcdfghijklmnpqrstuvwxyzñ', b = 'aeilorsuy', c = 'aeioruhtlkkkkkkkkk', d = 'aeiourldns', e = 'abcdefyrnsltmpxizñ', f = 'aeiouylrf', g = 'aeiouhrlmns', h = 'aeiourlt', i = 'encstoadlmvzrgfrtpbkñ', j = 'uaoei', k = 'eiaolunyhsrw', l = 'eiayoug', m = 'aeiouypb', n = 'aeiouytgdcsn', o = 'abcdefnruplsmtzñ', p = 'rehaoilhtusp', q = 'u', r = 'aeioutymscdrnpb', s = 'etshaicupomlynk', t = 'eiraohuytlar', u = 'bcdfghnslrmtiaepzñ', v = 'eiaour', w = 'aeiouyhrnls', x = 'aeiouytcpl', y = 'elstacpnm', z = 'eaioyuz', ñ = 'aeiou'; function rng (doAccents = true, min = 4, max = 8, length = Math.floor(Math.random() * (max - min + 1)) + min, firstChar = chars[Math.floor(Math.random() * chars.length)]) { let out = []; for (let index = 0; index < length; index++) { if (index == 0) { out.push(firstChar); } else { out.push(eval(out[index-1])[Math.floor(Math.random() * eval(out[index-1]).length)]); } } if (doAccents) { let hasAccent = false; out = out.map(char => { let newChar; if (Math.floor(Math.random() * 10) >= 5) { newChar = ñ.includes(char) && !hasAccent ? accents[ñ.indexOf(char)] : char; hasAccent = true; } return newChar || char; }); } if (out[out.length-1] == "ñ") { out.push(ñ[Math.floor(Math.random() * ñ.length)]); } return out.join(''); } for(let i = 0; i < 10; i++) { console.log(rng(true, 5, 6)); console.log(""); console.log(rng(false, 4, 8)); console.log(""); } // good names: garnguck, lemock, wemee, yermpoo, jelifyeshi, vazaji, zufazi, dupunt, trythluid /* more good names: elóra, yáddro, lezíe, janeño, bahúz, gouñuña, volgrad, flizz, tunck, vorag, sylem, kitala, vunos, jaith, qumor, henup, ornda, zilep, cantadu, gromu, lodley */
- /*
- Changes include adding `accents` and the `ñ`.
- I also added `min` and `max` as parameters.
- */
- const accents = 'áéíóú',
- chars = 'abcdefghijklmnopqrstuvwxyz',
- a = 'bcdfghijklmnpqrstuvwxyzñ',
- b = 'aeilorsuy',
- c = 'aeioruhtlkkkkkkkkk',
- d = 'aeiourldns',
- e = 'abcdefyrnsltmpxizñ',
- f = 'aeiouylrf',
- g = 'aeiouhrlmns',
- h = 'aeiourlt',
- i = 'encstoadlmvzrgfrtpbkñ',
- j = 'uaoei',
- k = 'eiaolunyhsrw',
- l = 'eiayoug',
- m = 'aeiouypb',
- n = 'aeiouytgdcsn',
- o = 'abcdefnruplsmtzñ',
- p = 'rehaoilhtusp',
- q = 'u',
- r = 'aeioutymscdrnpb',
- s = 'etshaicupomlynk',
- t = 'eiraohuytlar',
- u = 'bcdfghnslrmtiaepzñ',
- v = 'eiaour',
- w = 'aeiouyhrnls',
- x = 'aeiouytcpl',
- y = 'elstacpnm',
- z = 'eaioyuz',
- ñ = 'aeiou';
- function rng (doAccents = true, min = 4, max = 8, length = Math.floor(Math.random() * (max - min + 1)) + min, firstChar = chars[Math.floor(Math.random() * chars.length)]) {
- let out = [];
- for (let index = 0; index < length; index++) {
- if (index == 0) {
- out.push(firstChar);
- } else {
- out.push(eval(out[index-1])[Math.floor(Math.random() * eval(out[index-1]).length)]);
- }
- }
- if (doAccents) {
- let hasAccent = false;
- out = out.map(char => {
- let newChar;
if (Math.floor(Math.random() * 10 >= 5)) {- if (Math.floor(Math.random() * 10) >= 5) {
- newChar = ñ.includes(char) && !hasAccent ? accents[ñ.indexOf(char)] : char;
- hasAccent = true;
- }
- return newChar || char;
- });
- }
- if (out[out.length-1] == "ñ") {
- out.push(ñ[Math.floor(Math.random() * ñ.length)]);
- }
- return out.join('');
- }
- for(let i = 0; i < 10; i++) {
- console.log(rng(true, 5, 6));
- console.log("");
- console.log(rng(false, 4, 8));
- console.log("");
- }
- // good names: garnguck, lemock, wemee, yermpoo, jelifyeshi, vazaji, zufazi, dupunt, trythluid
- /* more good names:
- elóra, yáddro, lezíe, janeño, bahúz, gouñuña,
- volgrad, flizz, tunck, vorag, sylem, kitala, vunos, jaith, qumor, henup, ornda, zilep, cantadu, gromu, lodley
- */