In reply to dve12:
You have made the constraints much more complex than they need to be, And technically, you are not allowed a random index into a random array variable.
module abc;
class aa;
rand byte unsigned val[10], val3;
constraint s1 {
foreach(val[i]) {
val[i] < 10;
// every value except val3 must appear only once
val[i] != val3 -> val.sum() with (int'(item==val[i]))== 1;
}
// val3 must appear three times in the array
val.sum() with (int'(item==val3)) == 3;
}
endclass
aa a1 = new();
initial repeat (10) begin
a1.randomize();
$display("%p %d", a1.val, a1.val3);
end
endmodule