TextGenerator
TextGenerator copied to clipboard
Add ability to do a reproducable random choice
I needed a function that allowed me to do a random choice, but keep the choice linked to a seed value so that the text would stay constant over subsequent runs (even when the template has changed, only the new parts change, the rest stays the same).
Interested in a PR?
Hi @loekvangool ,
Yes, I think this could be a great improvement for the lib to be able to generate reproducible texts ! Do you have the code architecture in mind ?
I have though about it quiclky but maybe the TextGenerator service could provide a getSeed() method that returns a random seed. The generate() function could accept an optional argument $seed that will be transmitted to the "seedable" text functions (random, prandom and shuffle). These functions could implement a "Seedable" interface and a setSeed() function (provided by a Trait ?) and they should be modified to handle the seed. In the TextGenerator::generate() function, we could call setSeed() with the seed (that can be nul) on the seedable functions before generating the text. What do you think ?
https://github.com/neveldo/TextGenerator/pull/12 created