Jump to content

Image random


Frank Vèssia
 Share

Recommended Posts

i'm getting this strange behaviour with image getRandom

I want to display all images of one field randomly.

So i first count my total images and than use getRandom.

<?php

$tot = count($gallery->images); 

$gallery = $gallery->images->getRandom($tot);

foreach ($gallery as $image){
...
}

I always get the same order but if i change the $tot variable with a smaller value (smaller than the total count) it works... ???

Link to comment
Share on other sites

The behavior of PHP's array_rand() function (used by getRandom) does seem a little strange when pulling the entire array. I agree with Apeisa that shuffle() is a better way to go for randomizing the entire thing, whereas getRandom is better for pulling 1 or a few elements.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...