A pseudo-word generator that creates words which resemble real ones—though they usually aren't!
This generator is inspired by the logic behind feldarkrealms.com.
It requires a large sample of text, which is split into individual words. From each word, the following are extracted:
- The first two letters
- All three-letter sequences
- The last five letters
hello → he, hel, ell, llo, hello
goodbye → go, goo, ood, odb, dby, bye, odbye
These fragments are stored in separate files along with their frequencies. For instance:
// Initial two-letter prefixes "he": 10, "go": 4,
// Three-letter sequences "hel": 3, "god": 20,
// Word endings "rings": 12, "nners": 15,` After generation, fragments that appear less than a certain number of times are filtered out.
Word construction:
-
A two-letter prefix is chosen randomly, weighted by frequency (e.g., if
"go"appears 5× and"he"appears 1×,"go"is 5× more likely to be selected). -
The script searches for three-letter sequences that start with those two letters (e.g.,
"go"→"goo","gon","gop", etc.). -
One is chosen (again, by frequency), and the third letter is added to the word.
-
This continues by matching the last two letters of the current word with the first two letters of available sequences, adding one letter each time.
-
Finally, the last two letters of the partially formed word are used to find a matching ending fragment, which is appended (also weighted by frequency).
Example flow:
- Start with: "he"
- Found sequences: "hel", "hep", "hen" (with respective weights)
- Chose: "hep" → now word is "hep"
- Next: match "ep" to sequences → choose and append next letter
- Continue until desired length
- Append suitable ending fragment
💡 Fun fact: The language of the sample text affects the output of the script, if you use a german sample text german pseudo-words will be generated.
generatePseudoWords(iterations, amount)
iterations(number)– Roughly the length of each generated word (i.e., how many steps to build it)amount(number)– Number of pseudo-words to generate Example:
// Generate 3 pseudo-words with 5 construction steps each
generatePseudoWords(5, 3); // Possible output: "matosis ocinate bleling" License: MIT
Contributing: Contributions welcome! Please feel free to submit a Pull Request.