2D array constraint randomization

In reply to vai_des:


class like_sudoku;
 
  rand bit [4:0] a [3][3];
 
  constraint c1 {

        foreach(a[i,j]) {
            a.sum with (item.index(1) == i ? int'(item): 0) == 15; // rows
            a.sum with (item.index(2) == j ? int'(item): 0) == 15; // cols
        }
        unique {a};
  }


1 Like