HUGO
Menu
GitHub 90565 stars Mastodon

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>