There are many ways to generate random words. You can take random syllables from a set, you can use n-tuples, probably neural networks (what can't they do?), alternating between consonants and vowels, etc. The method this challenge is based off of is by far the worst. It uses a Markov chain to generate random words. If you are familiar Markov chains, you probably know why this method is so terrible.
If you want to read about Markov chains, click here.
Your program will take an input one or more words and generate a single random word, through the method of a weighted Markov chain. Since that probably makes sense to no one but me, here is an explanation through the use of a picture of the Markov chain with the input of
(All edge weights are the same for all pictures) Your program will output the path through a Markov chain based on the input text. As you can see, there is a 1/2 chance it will output
a, 1/8 chance of
aba, 1/16 chance of
abba, 1/32 chance of
Here are some other example Markov chains:
yabba dabba doo
If you want more examples, use this. (I worked way too hard on it)
Details of challenge:
- Input can be taken as a list of strings, or as a space, comma, or newline separated string
- You may assume that all the words will be entirely lowercase with no punctuation (ASCII 97-122)
- You may write either a program or a function
- To test, you could probably input the examples and see if all inputs line up with the Markov chains
This is code-golf, so your program is scored in bytes.
Let me know if any part of this is unclear, and I will try to make it make more sense.