I would like to generate the connected pixels as below. All 1's are connected through vertical and horizontal. No condition for the 0's.

Ex:

0000

0010

0111

0100

or

0000

0011

0010

0000

class test; rand bit a[5][5]; constraint c1 { foreach(a[x,y]) a[x][y] -> (x>0 & a[x-1][y] || x<4 & a[x+1][y] || y>0 & a[x][y-1] || y<4 & a[x][y+1]); } endclass module tb; test t_h; initial begin t_h=new; assert(t_h.randomize); foreach(t_h.a[i,]) $display("%p",t_h.a[i]); end endmodule

I see below error:

Error-[CNST-IAIE] Constraint illegal array index error

testbench.sv, 19

Constrained variable a[-1][0] is outside of the array size.

Please make sure variable a[-1][0] is within the array size.

BTW, Is there a better solution?