what I can think of is use a function to calculate number of unique elements; But I remember for functions inside constraint , it would imply constraint are only one direction, not sure if this will affect the solution space？

I did not follow what is implied by this “foreach (unum[i]) num.sum() with (4’(item==unum[i]))==1;”

“there must be at least 7 unique elements in this array”

You should unroll the foreach loop into 7 constraint expressions and see if that helps you see what it does. If that is not enough, unroll one of the num.sum() methods.

Thank you Dave , My bad I wrongly Assumed we neeed 7 unique elements && 3 same elements
For what I had in my mind added one more check to see that the other 3 elements are same

rand bit [3:0] constval;
....
constraint uniq { unique {unum};
foreach (unum[i]) num.sum() with (4'(item==unum[i]))==1;
num.sum() with (4'(item==constval))==3; // Make sure three elements are similar
}