The code is like below -
module test();
class temp;
int array[15] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,8};
rand int q1[$];
rand int q2[$];
rand int q3[$];
constraint c1 {
q1.size == 5;
q2.size == 5;
q3.size == 5;
foreach (q1[i]) {
q1[i] inside {array};
q2[i] inside {array};
q3[i] inside {array};
}
unique {q1,q2};
unique {q2,q3};
unique {q3};
}
endclass
initial
begin
temp t = new();
t.randomize();
$display ("%p\n %p\n %p\n", t.q1, t.q2, t.q3);
$finish;
end
endmodule
The current output looks like so -
'{10, 6, 11, 1, 13}
'{4, 2, 5, 3, 12}
'{11, 13, 10, 14, 8}
q1, q2 and q3 are all required to contains elements from array. No element should be shared across q1,q2,q3 unless the element is repeated in the array itself in which case it is fine.
I got as far as getting 2/3 queues unique but q3 would always have elements from q1 or q2. How can I constrain q3 to be '{7, 8, 8, 9, 14} which is all the remaining elements of array not in both q1 and q2.
EDIT: I could do it in post_randomize but is there a way through constraints