module test;
class unique_arr;
randc bit[3:0] arr[10];
// constraint c_2 { unique{arr};}
// constraint c_3{ foreach(arr[i])
// foreach(arr[j])
// if(i!=j)
// arr[i] !=arr[j];
// }
endclass: unique_arr
initial begin
unique_arr arr_obj;
arr_obj = new();
repeat(10)
if(arr_obj.randomize())begin
$display("arr=%p", arr_obj.arr);
end
end
endmodule: test
Output
arr='{'he, 'ha, 'ha, 'hb, 'h7, 'hc, 'h4, 'h6, 'h7, 'hf}
arr='{'h4, 'h4, 'h2, 'hc, 'hb, 'hf, 'h1, 'h1, 'h3, 'h0}
arr='{'h3, 'h8, 'h4, 'he, 'hd, 'hd, 'ha, 'h0, 'h6, 'h9}
arr='{'hf, 'h7, 'h1, 'hf, 'he, 'he, 'h0, 'h8, 'hc, 'h2}
arr='{'ha, 'hf, 'h3, 'h8, 'hc, 'h6, 'h3, 'he, 'h9, 'h1}
arr='{'h0, 'h9, 'h0, 'hd, 'hf, 'h9, 'h7, 'h4, 'h1, 'he}
arr='{'h1, 'h3, 'hc, 'ha, 'ha, 'h8, 'hc, 'h5, 'he, 'ha}
arr='{'hd, 'h5, 'h8, 'h9, 'h3, 'h7, 'h2, 'h7, 'h4, 'h8}
arr='{'h2, 'h6, 'he, 'h3, 'h1, 'ha, 'h5, 'h9, 'h5, 'h5}
arr='{'h7, 'hd, 'hb, 'h2, 'h2, 'h3, 'hb, 'hf, 'hb, 'hb}
Instead of using the unique constraint or the code commented above for generating the unique values for the array. I was thinking of exploiting the randc property to generate the unique values for the array. But the output does not seem to be behaving according to randc cyclic nature.
I have declared the arr as randc and defined it of size -10. The width of each element in this [3:0] - so ideally it should exhaust all values from 0-15 and then should start repeating the values.
Can someone explain why the randc nature is not getting exercised for the arr on randomization? why do we see the 'ha and 'ha generated twice in first iteration eventhough array is defined to be randc ?
Output
arr='{'he, 'ha, 'ha, 'hb, 'h7, 'hc, 'h4, 'h6, 'h7, 'hf}