Randomization with shuffle and math functions

In .Site.Data I have 6 files quiz1.yml, quiz2.yml … quiz6.yml. I want to load their content randomly using a shuffle or math function. There are two options, shuffle:

{{ $item := seq 6 | shuffle | first 1 }}
{{ $thefile := getPage (printf "filename-%1.md" $item }}
...
...
...
{{ end }}

or

{{ $filename := shuffle (slice "file1.md" "file-other.md" "some-other-file.md") | first 1 }}

so far I don’t know how to make it work.

and math:

{{ $theIndex := printf "quiz%s" (Math.floor(Math.random() * 6)) }}
{{ with (index .Site.Data $theIndex) }}
...
...
...
{{ end }}

Math function throws an error message: function “Math” not defined.
Math is an inner function, it is pre-defined, isn’t it?

Please help if you can.
Thank you!

Kind of, but according to

Math.random() is not part of it (though pow is, for example)

You need to look in the documentation. Guessing about function names is never a great strategy.

1 Like

Thank you