Randomize list with constraints

In reply to stupidkris1010:

I am using this one which works fine, but looking for comments to optimize it further/ find other efficient way:


task randomize_list;
    bit list[];
    list  = new[32];
    $display("Random list:\n");
    randomize(list) with { 
      list.sum < 32;
      foreach(list[i]) if(i>0 && list[i]) list[i-1] != 1'b0;
    };
    for(int i=0;i<32;i++)
      $display("%1b", list[i]);
        
  endtask