You can achieve this otherwise by calling the php rand function straight away from your blade file rather than defining js method to do this. It would be as shown below;
@if(rand(0,1) === 1)
@include('components.Hero1')
@else
@include('components.Hero2')
@endif