RAndomize a Queue in System Verilog

*In reply to Ravi Nagadia:*Do not ever use $random in SystemVerilog, and there is no need for pre_ or post_randomize.

Donald,

You can randomize a queue the same way you randomize a dynamic array. If you constrain the size of a queue, the solver will allocate the elements of the queue to meet the constraint. Then you can use
foreach
to constrain each element.

class seq extends base_seq;
rand bit [15:0] my_q [$];
constraint queue_val {
      my_q.size() inside {[10:20]};
      foreach (my_q[ii]) my_q[ii] >2;
}
endclass