<p>You could use Craft's <a href="http://buildwithcraft.com/docs/templating/functions#shuffle"><code>shuffle()</code></a> function to randomize your <code>postDate</code> ordered array of entry models:</p>

<pre><code>{% set entries = craft.entries({
    section: 'entertainmentEvents',
    entertainmentBanner: ':notempty:',
    status: 'live, pending',
    order: 'postDate desc',
    limit: 10
}) %}

{% set entries = shuffle(entries) %}

{% for entry in entries|slice(0, 3) %}
    ...
{% endfor %}
</code></pre>

CC BY-SA 3.0
2015-05-05T15:05:21.917Z
Damn, beat me to it! I'd update your answer to show how you would limit your 'entries' to 3?
Jamie Wade
CC BY-SA 3.0
2015-05-05T15:06:23.300Z
Ouups, totally missed that part. Thanks Jamie.
carlcs
CC BY-SA 3.0
2015-05-05T19:05:25.550Z
@JamieWade carlcs is an answer ninja.
Brad Bell
CC BY-SA 3.0
2015-05-06T10:15:45.237Z
@BradBell I'll be on my guard next time.
Jamie Wade
CC BY-SA 3.0
2015-05-06T19:10:30.937Z
Perfect. And in production already. Thanks @carlcs
Tim Print
CC BY-SA 3.0
2015-05-05T15:04:06.697Z
2015-05-05T15:08:02.267Z
2015-05-05T15:08:02.267Z
carlcs
<pre><code>{% for entry in craft.entries.section('entertainmentEvents').status('live','pending').search('entertainmentBanner:*').order('RAND()').limit(3) %}
</code></pre>

<p>This is working to show 3 random entries from the full list of all entries with the entertainmentBanner field populated. How would I limit it to the first ten entries by entry date and then 3 at random from within them?</p>

<templating><entries><limit>
How can I show 3 entries at random from within the next 10
# How can I show 3 entries at random from within the next 10

(Asked by: username_0 on 2015-05-05)

{% for entry in craft.entries.section('entertainmentEvents').status('live','pending').search('entertainmentBanner:*').order('RAND()').limit(3) %}

This is working to show 3 random entries from the full list of all entries with the entertainmentBanner field populated. How would I limit it to the first ten entries by entry date and then 3 at random from within them?

**Tags:** templating, entries, limit


---

## 1 answers

### Answer by username_1 on 2015-05-05. Score: 6 | Accepted answer

You could use Craft's shuffle() function to randomize your postDate ordered array of entry models:
{% set entries = craft.entries({
    section: 'entertainmentEvents',
    entertainmentBanner: ':notempty:',
    status: 'live, pending',
    order: 'postDate desc',
    limit: 10
}) %}

{% set entries = shuffle(entries) %}

{% for entry in entries|slice(0, 3) %}
    ...
{% endfor %}

> **Comments:**
> **username_2**: Damn, beat me to it! I'd update your answer to show how you would limit your 'entries' to 3?  
> **username_1**: Ouups, totally missed that part. Thanks Jamie.  
> **username_3**: @JamieWade username_1 is an answer ninja.  
> **username_2**: @BradBell I'll be on my guard next time.  
> **username_0**: Perfect. And in production already. Thanks @username_1  

---

