Answers.Body: <p>There are two options for accomplishing this:</p>
  
  <pre><code>{% for block in shuffle(entry.matrixField) %}
  </code></pre>
  
  <p>or </p>
  
  <pre><code>{% for block in shuffle(entry.matrixField.find()) %}﻿
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-12T19:34:15.240Z
Answers.Text: I think these are very much the same. `entry.matrixField.find()` explicitly returns an array, but `shuffle()` will convert to an array anyway
Answers.UserDisplayName: Marion Newlevant
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-12T17:24:41.603Z
Answers.LastActivityDate: 2014-06-12T17:24:41.603Z
Answers.UserDisplayName: Anna_MediaGirl
Answers.Body: <p>You can either have MySQL select the blocks in a random order using <a href="http://dev.mysql.com/doc/refman/5.1/en/mathematical-functions.html#function_rand"><code>RAND()</code></a>:</p>
  
  <pre><code>{% set blocks = entry.myMatrixField.order('RAND()') %}
  </code></pre>
  
  <p>Or you can shuffle the blocks from Twig instead, using Craft’s <a href="http://buildwithcraft.com/docs/templating/functions#shuffle">shuffle()</a> function:</p>
  
  <pre><code>{% set blocks = shuffle(entry.myMatrixField) %}
  </code></pre>
  
  <p>There’s not a major performance difference either way in most cases, however if you also want to <em>limit</em> the number of blocks, each method will give you different results.</p>
  
  <p>For example, this will pick 3 blocks at random out of the entire set:</p>
  
  <pre><code>{% set blocks = entry.myMatrixField.limit(3).order('RAND()') %}
  </code></pre>
  
  <p>But this will always pick the first 3 blocks, and those 3 blocks will be displayed in a random order:</p>
  
  <pre><code>{% set blocks = shuffle(entry.myMatrixField.limit(3)) %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-12T17:59:06.537Z
Answers.LastActivityDate: 2014-06-12T17:59:06.537Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I have a slideshow with slide data managed in a Matrix field. How would I go about randomizing the data returned in the template so the slides show in a different order on each page load?</p>
  
Tags: <matrix><random><ordering>
Title: How can I return data from a Matrix field in random order?
ThreadText: # How can I return data from a Matrix field in random order?
  
  (Asked by: username_0 on 2014-06-12)
  
  I have a slideshow with slide data managed in a Matrix field. How would I go about randomizing the data returned in the template so the slides show in a different order on each page load?
  
  **Tags:** matrix, random, ordering
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2014-06-12. Score: 27 | Accepted answer
  
  You can either have MySQL select the blocks in a random order using [`RAND()`](http://dev.mysql.com/doc/refman/5.1/en/mathematical-functions.html#function_rand):
  
  ```
  {% set blocks = entry.myMatrixField.order('RAND()') %}
  
  ```
  
  Or you can shuffle the blocks from Twig instead, using Craft’s [shuffle()](http://buildwithcraft.com/docs/templating/functions#shuffle) function:
  
  ```
  {% set blocks = shuffle(entry.myMatrixField) %}
  
  ```
  
  There’s not a major performance difference either way in most cases, however if you also want to *limit* the number of blocks, each method will give you different results.
  
  For example, this will pick 3 blocks at random out of the entire set:
  
  ```
  {% set blocks = entry.myMatrixField.limit(3).order('RAND()') %}
  
  ```
  
  But this will always pick the first 3 blocks, and those 3 blocks will be displayed in a random order:
  
  ```
  {% set blocks = shuffle(entry.myMatrixField.limit(3)) %}
  
  ```
  
  
  ---
  
  ### Answer by username_0 on 2014-06-12. Score: 2
  
  There are two options for accomplishing this:
  
  ```
  {% for block in shuffle(entry.matrixField) %}
  
  ```
  
  or
  
  ```
  {% for block in shuffle(entry.matrixField.find()) %}﻿
  
  ```
  
  > **Comments:**
  > **username_1**: I think these are very much the same. `entry.matrixField.find()` explicitly returns an array, but `shuffle()` will convert to an array anyway  
  
  ---
  
  