Can shuffle be cached?

@irkode’s suggestion to generate five random numbers is significantly faster:

<p>Five random pages:</p>
<ul>
  {{ range seq 5 }}
    {{ with math.Rand | mul site.RegularPages.Len | math.Floor | int }}
      {{ with index site.RegularPages . }}
        <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
      {{ end }}
    {{ end }}
  {{ end }}
</ul>

Using this approach with the example site referenced above, the build time increased by 10% instead of 22%.

2 Likes