Randc in an variable within an array of objects

In reply to dave_59:

In reply to ABD_91:
That answer is not correct.
First of all, randc only works multiple calls to randomize() on the same object; It does not have any effect on the first or only call to randomize().
And second. randc looks at the total solution space for that variable. It just needs to produce a

different

solution for call to randomize(). So the following solutions meet that criteria

array1 = '{'h0, 'h0, 'h0, 'h0, 'h0, 'h0}
array1 = '{'h0, 'h0, 'h0, 'h0, 'h0, 'h1}
array1 = '{'h0, 'h0, 'h0, 'h0, 'h1, 'h0}
array1 = '{'h0, 'h0, 'h0, 'h0, 'h0, 'h2}
... ~50,000 more possible solutions

If you are just looking for each array element to be unique, use the unique constraint and not randc.

constraint c { unique {array1}; }

Hi Dave, please see the following example:

class cyclic_arr ;
   randc int arr [2] ;
   constraint c_range {
      foreach (arr[i])
         arr[i] inside {[1:3]} ;
   }
   constraint c_sorted {
      foreach (arr[i])
         if (i>0)
            arr [i] > arr[i-1] ;
   }
endclass
module my_tb ;
   
   cyclic_arr my_cyclic_arr ;

   initial begin
      my_cyclic_arr = new() ;
      for (int i=0; i<10; i++) begin
         void'(my_cyclic_arr.randomize()) ;
         $display("%p", my_cyclic_arr.arr) ;
      end
   end
endmodule

The possible solutions are only these three:
{'{1,2}, '{1,3}, '{2,3}}
So according to what you have written i would expect the first three runs of the loop to get all these results, but the results are:

'{1, 3}
'{2, 3}
'{2, 3}
'{1, 2}
'{2, 3}
'{1, 2}
'{2, 3}
'{1, 2}
'{2, 3}
'{1, 2}

Have any idea why?

THanks,
Mihael