collections.Shuffle
Returns a slice by randomizing the element order of the given slice.
- Syntax
- collections.Shuffle SLICE
- Returns
- []any
- Alias
- shuffle
Usage
The collections.Shuffle function returns a slice by randomizing the element order of the given slice. The result changes from one build to the next.
To select random pages from a page collection, the collections.D function is faster, and lets you control the result with a seed value.
Examples
{{ collections.Shuffle (slice "a" "b" "c") }} → [b a c]Rendering a list of five random pages:
<ul>
{{ range site.RegularPages | collections.Shuffle | first 5 }}
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
{{ end }}
</ul>Last updated:
November 24, 2026
:
content: Apply style guide to collections functions (04f2e2939)
Improve this page