SV Constraint to Generate a 2D Array with Unique Elements

Does anyone have a solution for this problem? Looked around and not able to find it. Not able to come up with solution either.

In reply to totochan1985:


 class a2a ;
  rand int unsigned aa[4][4]; // fixed 2d array for example
  constraint c_aa{
   foreach(a[i,j]) a[i][j] inside {[1:20]};
   unique {aa};
  }
 endclass 
or 
 class a2a ;
  rand int unsigned aa[4][4]; // fixed 2d array for example
  constraint c_aa{
   foreach(a[i,j]) a[i][j] inside {[1:20]};
   foreach(a[i,j]){
     foreach(a[k,l]){
       if( !(i ==k && j ==k)) a[i][j] != a[l][k]; 
      }
     }
  }
 endclass 

In reply to kddholak:

In reply to totochan1985:


class a2a ;
rand int unsigned aa[4][4]; // fixed 2d array for example
constraint c_aa{
foreach(a[i,j]) a[i][j] inside {[1:20]};
unique {aa};
}
endclass 
or 
class a2a ;
rand int unsigned aa[4][4]; // fixed 2d array for example
constraint c_aa{
foreach(a[i,j]) a[i][j] inside {[1:20]};
foreach(a[i,j]){
foreach(a[k,l]){
if( !(i ==k && j ==k)) a[i][j] != a[l][k]; 
}
}
}
endclass 

The first one is obvious but I was looking for one without unique operator. What is the logic behind the 2nd solution. Could you explain.