Randc does not work with 2d array

In reply to dave_59:

Thanks Dave But do I need to do something more about constraint to make array in ranc()?
I think arr_1d is array. so I declared it with “randc” and generate random numbers by foreach(). But same result I get.

arr_1d[0]=6
arr_1d[1]=5
arr_1d[2]=5
arr_1d[3]=1

I didn’t get it. why does this “randc” break?


class arr_test_c;                                 
  randc logic [2:0] arr; //This is not the array. 
  randc logic [2:0] arr_1d[];                     
                 
                                                  
constraint size_con {                             
  arr inside {[2:4]};                              
  arr_1d.size() inside {[3:4]};                    
}                                                  
                                                   
endclass                                           
                                                   
                                                   
                                                   
module test;                                       
                                                   
                                                   
initial begin                                      
    arr_test_c arr_test;                           
    arr_test = new();                              
                                               
   void'(arr_test.randomize());                   
  foreach(arr_test.arr_1d[i]) begin                
  $display("arr_1d[%0d]=%0d", i, arr_test.arr_1d[i]); 
  end                                              
end                                                
                                                   
                                                   
endmodule