From f872e128a32b053a6d49991d5c29e73a1b678daa Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 8 Mar 2025 07:12:10 +0100 Subject: [PATCH] Add template function: shuffle (#37864) * Add template function: shuffle * Use 'reproducible' instead * tiny tweak --------- Co-authored-by: c0ffeeca7 <38767475+c0ffeeca7@users.noreply.github.com> --- .../_docs/configuration/templating.markdown | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/source/_docs/configuration/templating.markdown b/source/_docs/configuration/templating.markdown index b68cd1d7c6b..39a38bc7efb 100644 --- a/source/_docs/configuration/templating.markdown +++ b/source/_docs/configuration/templating.markdown @@ -1185,6 +1185,28 @@ See: [Python regular expression operations](https://docs.python.org/3/library/re - Filter `value | regex_findall(find='', ignorecase=False)` will find all regex matches of the find expression in `value` and return the array of matches. - Filter `value | regex_findall_index(find='', index=0, ignorecase=False)` will do the same as `regex_findall` and return the match at index. +### Shuffling + +The template engine contains a filter and function to shuffle a list. + +Shuffling can happen randomly or reproducibly using a seed. When using a seed +it will always return the same shuffled list for the same seed. + +Some examples: + +{% raw %} + +- `{{ [1, 2, 3] | shuffle }}` - renders as `[3, 1, 2]` (_random_) +- `{{ shuffle([1, 2, 3]) }}` - renders as `[3, 1, 2]` (_random_) +- `{{ shuffle(1, 2, 3) }}` - renders as `[3, 1, 2]` (_random_) + +- `{{ [1, 2, 3] | shuffle("random seed") }}` - renders as `[2, 3, 1] (_reproducible_) +- `{{ shuffle([1, 2, 3], seed="random seed") }}` - renders as `[2, 3, 1] (_reproducible_) +- `{{ shuffle([1, 2, 3], "random seed") }}`- renders as `[2, 3, 1] (_reproducible_) +- `{{ shuffle(1, 2, 3, seed="random seed") }}` - renders as `[2, 3, 1] (_reproducible_) + +{% endraw %} + ## Merge action responses Using action responses we can collect information from various entities at the same time.