Answers.Body: <p>That query would basically tell MySQL to do this:</p>
  
  <ol>
  <li>Shuffle the blocks</li>
  <li>Return the second one</li>
  </ol>
  
  <p>Since the shuffling happens <em>before</em> the offset/limit params get applied, they can’t be used to exclude the first block, since the first block will already be put in some random position by that point.</p>
  
  <p>Instead you should get the ID of the first block, and exclude it using that:</p>
  
  <pre class="lang-twig prettyprint-override"><code>{% set firstBlockId = city.cityBlocks.limit(1).ids()|first %}
  
  {% if firstBlockId %}
      {% set randomQuotes = city.cityBlocks.id('not '~firstBlockId).order('RAND()') %}
      ...
  {% else %}
      There were no blocks...
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-02T20:50:35.673Z
Answers.LastActivityDate: 2014-09-02T20:50:35.673Z
Answers.UserDisplayName: Brandon Kelly
Answers.Body: <p>okay, shuffle seems to work:
  first set these:</p>
  
  <pre><code>{% set quotes = city.cityBlocks.offset(1) %}
  {% set randomQuotes = shuffle(quotes) %}
  </code></pre>
  
  <p>then slice the the for loop like this</p>
  
  <pre><code>{% for block in randomQuotes|slice(1,1) %}
  ...
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-02T20:36:25.837Z
Answers.LastActivityDate: 2014-09-02T20:36:25.837Z
Answers.UserDisplayName: portnull
Body: <p>I have quotes inside a global matrix which i want to output randomly on the homepage but without the first quote-block. this does not work:</p>
  
  <pre><code>{% set quotes = city.cityBlocks.offset(1) %}
  {% set randomQuotes = quotes.limit(1).order('RAND()') %}
  </code></pre>
  
  <p>the offset in 'quotes' works fine but the first block is still in randomQuotes anyway.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-09-02T05:19:30.693Z
Comments.Text: All that code would do is output the second block (which is all you'll ever get when offset=1 and limit=1). Have you tried removing the limit parameter?
Comments.UserDisplayName: Brandon Kelly
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-09-02T20:28:47.820Z
Comments.Text: thanks brandon, but that will just give me all the quotes.
Comments.UserDisplayName: portnull
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-09-02T20:46:04.013Z
Comments.Text: Sorry, I understand what you’re trying to do now.
Comments.UserDisplayName: Brandon Kelly
Tags: <matrix><random>
Title: Output random blocks from a matrix but without the first
ThreadText: # Output random blocks from a matrix but without the first
  
  (Asked by: username_0 on 2014-09-02)
  
  I have quotes inside a global matrix which i want to output randomly on the homepage but without the first quote-block. this does not work:
  
  ```
  {% set quotes = city.cityBlocks.offset(1) %}
  {% set randomQuotes = quotes.limit(1).order('RAND()') %}
  
  ```
  
  the offset in 'quotes' works fine but the first block is still in randomQuotes anyway.
  
  **Tags:** matrix, random
  
  > **Comments:**
  > **username_1**: All that code would do is output the second block (which is all you'll ever get when offset=1 and limit=1). Have you tried removing the limit parameter?  
  > **username_0**: thanks username_1, but that will just give me all the quotes.  
  > **username_1**: Sorry, I understand what you’re trying to do now.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2014-09-02. Score: 3 | Accepted answer
  
  That query would basically tell MySQL to do this:
  
  1. Shuffle the blocks
  2. Return the second one
  
  Since the shuffling happens *before* the offset/limit params get applied, they can’t be used to exclude the first block, since the first block will already be put in some random position by that point.
  
  Instead you should get the ID of the first block, and exclude it using that:
  
  ```twig
  {% set firstBlockId = city.cityBlocks.limit(1).ids()|first %}
  
  {% if firstBlockId %}
      {% set randomQuotes = city.cityBlocks.id('not '~firstBlockId).order('RAND()') %}
      ...
  {% else %}
      There were no blocks...
  {% endif %}
  
  ```
  
  
  ---
  
  ### Answer by username_0 on 2014-09-02. Score: 2
  
  okay, shuffle seems to work:
  first set these:
  
  ```
  {% set quotes = city.cityBlocks.offset(1) %}
  {% set randomQuotes = shuffle(quotes) %}
  
  ```
  
  then slice the the for loop like this
  
  ```
  {% for block in randomQuotes|slice(1,1) %}
  ...
  {% endfor %}
  
  ```
  
  
  ---
  
  