I'd like to generate (at least) two different random strings that are always different from each other.
{% set firstColour = random(['coral', 'pink', 'black', 'sand']) %}
{% set secondColour = random(['coral', 'pink', 'black', 'sand']) %}
{{ firstColour }}
{{ secondColour }}
I thought an "easy" solution would be to reset the second color if it is equal to the first
{# before variables are called #}
{% if firstColour == secondColour %}
{% set secondColour = '' %}
{% set secondColour = random(['coral', 'pink', 'black', 'sand']) %}
{% endif %}
Not only doesn't this seem very practical or "clean", but it also just doesn't work. On the twig documentation or other threads, I can't find anything about setting random strings with exceptions.
It's important that the outcome is random (not a slice) and not equal to the other variables. Eventually, I would like to get all possibilities in a random order with separate variables on the same page,
without ever repeating one: {{ firstColor}} {{ secondColour }} {{ thirdColour }} {{ fourthColour }} when called on a page, would always return 4 different values.
Is there a way to achieve using Twig's built-in functions or extensions?
shuffleandarray_pop- AbraCadaver