collections.Shuffle
Returns a slice by randomizing the element order of the given slice.
Syntax
collections.Shuffle SLICE
Returns
[]any
Alias
shuffle
{{ collections.Shuffle (slice "a" "b" "c") }} → [b a c]The result will vary from one build to the next.
To render an unordered list of 5 random pages from a page collection:
<ul>
{{ $p := site.RegularPages }}
{{ range $p | collections.Shuffle | first 5 }}
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
{{ end }}
</ul>Using the collections.D function for the same task is significantly faster.
Last updated:
February 14, 2026
:
Merge commit '8f3c066d23f431fb2c53d97ea489e4c28b42bd82' (3e2f98235)
Improve this page