Array Constraints

HI,
I have a fixed array of size 32.
I need to write a constraint such that maximum of 4 values can overlap and minimum of 2 values should overlap.
Could anyone help.

Thanks,
Vdas

Same approach can be used for minimum.

HI Dave,
Thanks Dave that helps.
I need help for writing one more constraint.
I have a region where start and size can be configured. there are 8 such regions with respective start and size.
Example: if start_0 = 10 & size_0 = 10, then region 0 is from 10 to 20. Likewise for other regions.
Here the constraint is 2 regions can overlap like below
start_0 = 10 & size_0 = 10; (region 0 from 10 to 20)
start_1 = 15 & size_1 = 10; (region 1 from 15 to 25)
Could you pls help

It would help if you made an attempt at the code and showed us what data structures you need. There is nothing random in what you just described.

HI Dave
I apologize for providing bits and piece of information. Just made an attempt.

class C;
  rand int unsigned start[8];
  rand int unsigned size[8];
  
  constraint c_start { foreach(start[i]) start[i] <= 1000;}
  constraint c_size { foreach(size[i]) size[i] <= 100;}
  constraint c_overlap {foreach(start[i]) !(start[i+1] inside {(start[i] + size[i])}); }
endclass
module  test() ;
C c_reg ;
initial begin
    c_reg = new() ;
    c_reg.randomize() ;
  foreach ( c_reg.start[i] )
    $display(" start[%0d] = %0d, size[%0d]=%0d", i, c_reg.start[i], i, c_reg.size[i]) ;
end
endmodule

Here i want only 2 regions to overlap out of 8.
start[3] = 10 & size[3] = 10; (region 3 starts from 10 ends at 20)
start[5] = 15 & size[5] = 20; (region 5 starts from 15 ends at 35)
15 to 20 got overlapped b/w region 3 & 5.

class C;
  rand int unsigned start[8];
  rand int unsigned size[8];
  rand bit overlap[8];
  constraint c_start { foreach(start[i]) start[i] <= 1000;}
  constraint c_size  { foreach(size[i] ) size[i]  <= 100;}
  constraint c_overlap {foreach(overlap[i]) 
    overlap[i] == (start.or(r) with (r.index == i ? 0 : (start[i] inside {[r:r+size[r.index]]})));
                        overlap.sum() with (int'(item)) ==4; // each overlap gets counted twice
                       }
                   
endclass
module  test() ;
C c_reg ;
initial begin
    c_reg = new() ;
  assert(c_reg.randomize());
  c_reg.size.sort() with (c_reg.start[item.index]);

  c_reg.start.sort;
  foreach ( c_reg.start[i] )
    $display(" start[%0d] = %3d, size[%0d]=%3d end %3d", i, c_reg.start[i], i, c_reg.size[i], c_reg.start[i]+c_reg.size[i] ) ;
end
endmodule