I want to randomize an multi dimension array in such a way that it should contain “unique” values. without using the “unique” keyword
How to write constraint for that ?
In the below example I want all the index have the unique value i.e. ary[0][0]=2,ary[0][1] =4, …
for example
rand int ary[2][2];
constraint unique_value{
foreach(ary[i,j]) {
ary inside{1:4};
}
Please ignore the syntax error
In reply to sumit089:
class arrays ;
rand int array[4][4];
constraint arr_c{
foreach(array[i,j]) array[i][j] == i*4 + j;
}
endclass
module test();
arrays m_arrays;
initial begin
m_arrays = new();
if(m_arrays.randomize())begin
m_arrays.array.shuffle();
foreach(m_arrays.array[i,j]) $display("Array[%0d][%0d]:%0d",i,j,m_arrays.array[i][j]);
end
end
endmodule
constraint c_item {
foreach(arry[i,j])
arry[i][j] inside {[1:4]};
foreach(arry[i,j])
foreach(arry[k,l])
if (i==k && j==l) arry[i][j]==arry[k][l];
else arry[i][j]!=arry[k][l];
}