Get randrom value which not duplicate with the value in previous random list

If you want to know more, check the posted link for the Fisher-Yates algorithm. It explains its operation and shows examples in several different programming languages. I used the python example as the basis for creating a Jinja2 template. As mentioned, I needed help with the list construction because list handling is rather limited in Home Assistant’s implementation of Jinja2. To get a sense of that, compare the python version to the Jinja2 version.


If the shuffle function has satisfied your requirements, please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic is resolved. This helps other users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.