One of the biggest insights of the last ten years in ML (This was understood much earlier, but now it's widely applied) is that prediction and generation are two sides of the same coin.
The way an LLM generates text is by generating a probability distribution over the possible next tokens, and then you take a sample from the distribution and pick that as the concrete token to generate.