*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.
I have another problem… In the sequence, i want to check the size of the queue . If the size of the queue is not 0, then i want to randomize the queue. Is it possible to achieve this with constraints.
I want something like the following. But this is a randomization error when i try to do this.
You have to check the size of the queue just before randomizing the queue as below,
seq obj = new;
if(obj.my_q.size() != 0)
begin
if(obj.randomize() == 1)
$display("Randomizing is done");
//Do Something with the Queue here
else
$display("Randomization failed");
end
else
$display("\n Didn't Randomize as my_q.size() is not equal to zero \n");]
Thanks,
Sravan K
In reply to donald:
Your constraint fails because you are saying if the size is 0, the size must be between 10 and 20. That constraint can never be met. What you need to do is check the size before randomization.