Answers.Body: <p>I wanted to see if the same thing could be accomplished using Craft's shuffle function.  At first, I was looping through the image array and using an if statement to grab the first one:</p>
  
  <pre><code>{% for image in shuffle(entry.banner) %}
      {% if loop.first %}
          {{ image.url }}
      {% endif %}
  {% endfor %}
  </code></pre>
  
  <p>Then, I realized there was a less verbose option:</p>
  
  <pre><code>{% set image = shuffle(entry.banner)[0] %}
  {{ image.url }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-07T22:15:58.213Z
Answers.LastActivityDate: 2015-10-07T22:15:58.213Z
Answers.UserDisplayName: Mike Pringle
Answers.Body: <p>Another way of getting a random image from image set in Craft 3</p>
  
  <pre><code>{{ shuffle(entry.bgImg.all())[0].getUrl('1900x1050') }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-21T11:10:32.237Z
Answers.LastActivityDate: 2020-02-21T11:10:32.237Z
Answers.UserDisplayName: denesis
Answers.Body: <p>Simply using <code>'RAND()'</code> in the order parameter does the trick.</p>
  
  <pre><code>{% for image in entry.banner.limit(1).order('RAND()') %}
    {{ image.url }}
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-10T18:35:13.433Z
Answers.LastActivityDate: 2015-06-10T18:35:13.433Z
Answers.UserDisplayName: John Johnson
Body: <p>I have a single that has 5 banner images. I would like to load a different image each time the page loads. I want to do this with twig not JS, is this possible if so could somone point me in the right direction.</p>
  
  <p>Thanks in advance </p>
  
Tags: <assets><image>
Title: Load an asset at random each page load
ThreadText: # Load an asset at random each page load
  
  (Asked by: username_0 on 2015-06-10)
  
  I have a single that has 5 banner images. I would like to load a different image each time the page loads. I want to do this with twig not JS, is this possible if so could somone point me in the right direction.
  
  Thanks in advance
  
  **Tags:** assets, image
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_3 on 2015-06-10. Score: 6 | Accepted answer
  
  Simply using `'RAND()'` in the order parameter does the trick.
  
  ```
  {% for image in entry.banner.limit(1).order('RAND()') %}
    {{ image.url }}
  {% endfor %}
  
  ```
  
  
  ---
  
  ### Answer by username_1 on 2015-10-07. Score: 4
  
  I wanted to see if the same thing could be accomplished using Craft's shuffle function. At first, I was looping through the image array and using an if statement to grab the first one:
  
  ```
  {% for image in shuffle(entry.banner) %}
      {% if loop.first %}
          {{ image.url }}
      {% endif %}
  {% endfor %}
  
  ```
  
  Then, I realized there was a less verbose option:
  
  ```
  {% set image = shuffle(entry.banner)[0] %}
  {{ image.url }}
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2020-02-21. Score: 3
  
  Another way of getting a random image from image set in Craft 3
  
  ```
  {{ shuffle(entry.bgImg.all())[0].getUrl('1900x1050') }}
  
  ```
  
  
  ---
  
  