Skip to content

How I can get products with random order?

I am making a custom module and I want to get 5 random product skus. So far I tried:

$objectManager = ObjectManager::getInstance();

/**
 * @var ProductRepository
 */
$productRepository = $objectManager->create(ProductRepository::class);

/**
 * @var SearchCriteriaBuilder
 */
$searchCriteria = $objectManager->create(SearchCriteriaBuilder::class);
$searchCriteria->addSortOrder(new SortOrder());
$skus = $productRepository->getList($searchCriteria)->getItems();

But how I can define that I want the skus to be retrieved in random order?