# RAndomize a Queue in System Verilog

**URL:** <https://verificationacademy.com/forums/t/randomize-a-queue-in-system-verilog/32730>\
**Category:** SystemVerilog\
**Tags:** Dave-Rich, SystemVerilog, randmize, systemverilog-Arrays\
**Created:** [January 9, 2017, 4:59am UTC](https://verificationacademy.com/forums/t/randomize-a-queue-in-system-verilog/32730 "2017-01-09T04:59:10Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![Sravan\_Reddy\_k](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/46a35a/32.png) [@Sravan\_Reddy\_k](https://verificationacademy.com/forums/u/Sravan_Reddy_k)\
**Post date:** [January 9, 2017, 1:03pm UTC](https://verificationacademy.com/forums/t/randomize-a-queue-in-system-verilog/32730/6 "2017-01-09T13:03:51Z")

</div>

_In reply to [donald](https://verificationacademy.com/forums/t/randomize-a-queue-in-system-verilog/32730/5):_

You have to check the size of the queue just before randomizing the queue as below,

```verilog

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

---

_[View the full topic](https://verificationacademy.com/forums/t/randomize-a-queue-in-system-verilog/32730)._
