LLMs are just the infinite monkeys theory put into practice. Get enough monkeys banging on typewriters and eventually you will get Shakespeare. In this case the LLMs are just running through the numerous permutations to find what it thinks is the best result.