In reply to dave_59:
Thanks you as always Dave. I got most of the code and updated a couple of lines to suit the requirements.
module top;
class C;
rand bit[4:0] A[], uniq_A[];
rand bit [7:0] length,k;
constraint sizes {
length == A.size();
length % k >= 1;
uniq_A.size() == (length/k) +1;
}
constraint uniqueness {
unique {uniq_A};
foreach(uniq_A[i]) {
if (i<(uniq_A.size()-1)) {
A.sum() with (int'(item==uniq_A[i])) == k;
}
else {
A.sum() with (int'(item==uniq_A[i])) == 1;
}
}
}
endclass
C c = new();
initial repeat(5) begin
assert(c.randomize() with {length == 17; k== 4;});
c.A.sort();
$display("%p", c);
end
endmodule
Surprising one of the simulators does not like this constraint and takes a really long time and I had to kill it. Anyhow cdns, questa worked.