# Constraint involving queues and arrays

**URL:** <https://verificationacademy.com/forums/t/constraint-involving-queues-and-arrays/35998>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, constraints\
**Created:** [April 20, 2019, 4:28am UTC](https://verificationacademy.com/forums/t/constraint-involving-queues-and-arrays/35998 "2019-04-20T04:28:27Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![UVM\_learner6](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/u/a8b319/32.png) [@UVM\_learner6](https://verificationacademy.com/forums/u/UVM_learner6)\
**Post date:** [October 25, 2019, 6:19am UTC](https://verificationacademy.com/forums/t/constraint-involving-queues-and-arrays/35998/4 "2019-10-25T06:19:40Z")

</div>

_In reply to [kernalmode1](https://verificationacademy.com/forums/t/constraint-involving-queues-and-arrays/35998/3):_

> The code is like below -

```verilog
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

Hi, Would you be able to show how you got the 3rd queue to be unique elements in post\_randomize?

Thanks.

---

_[View the full topic](https://verificationacademy.com/forums/t/constraint-involving-queues-and-arrays/35998)._
