Skip to main content

Get random result from collection in magento 2

The best way is to use "orderRand()", so after you build your collection you can use this sets

 $result= $collection->setPageSize(3)->getSelect()->orderRand(); 

the $result will contain three random result from your collection

Tags