I know it's not proper solution. But, It maybe helpful for you. Try to use this below code :
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$categoryFactory = $objectManager->create('Magento\Catalog\Model\ResourceModel\Category\CollectionFactory');
$categories = $categoryFactory->create()->addAttributeToSelect('*');
$cat_arr = $categories->getData();
$random_keys = array_rand($cat_arr, 5);
$cat_ids = [];
foreach ($random_keys as $key => $value) {
$cat_ids[] = $cat_arr[$value]['entity_id'];
}
$cat_rand_obj = $categoryFactory->create()->addAttributeToSelect('*')->addAttributeToFilter('entity_id', ['in' => $cat_ids]);
echo "<pre>";
print_r($cat_rand_obj->getData());
Note: Avoid to use object manager. Use Factory Method structure.