Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

randomized Arraylist. (SS3)

Go to End



Community Member, 13 Posts

13 December 2012 at 10:54pm

Hi, how can i randomize a ArrayList? This is my Code:

public function ImpressionsInRandomOrder($__count = 15) {

$homepagePercent = 0.8;

$homepageCount = (int) round($__count * $homepagePercent);
$currentCount = $__count - $homepageCount;

$_home = ImpressionObject::get()->filter(array('PageID' => '1'))->sort('RAND()')->limit($homepageCount);
$_current = ImpressionObject::get()->filter(array('PageID' => $this->ID))->sort('RAND()')->limit($currentCount);

$_merge = new ArrayList();
$_merge->sort('RAND()'); <-- this don't go

return $_merge;