On the div that immediately wraps each post, you can use php to randomize the values instead of hardcoding the col-12
and col-sm-6
classes.
For example, you could change
<div class="col-12 col-sm-6 <?php echo $termsString; ?> grid-item wow fadeInUp">
to reflect the randomizer and then its result:
<?php
$randomColClasses="col-" . rand(8,12); //random value between 8-12
$randomColClasses .= ' col-sm-' . rand(4,8); //random value between 4-8
?>
<div class="<?php echo $randomColClasses . ' ' . $termsString; ?> grid-item wow fadeInUp">