# Randomizing a sequence item in Hierarchical Sequences

**URL:** <https://verificationacademy.com/forums/t/randomizing-a-sequence-item-in-hierarchical-sequences/35216>\
**Category:** UVM\
**Tags:** UVM, uvm\_sequence\_item, Calling-Sequence-inside-a-sequence, constraints, hierarchical-constraints\
**Created:** [October 22, 2018, 3:51am UTC](https://verificationacademy.com/forums/t/randomizing-a-sequence-item-in-hierarchical-sequences/35216 "2018-10-22T03:51:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![piyer](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/c4cdca/32.png) [@piyer](https://verificationacademy.com/forums/u/piyer)\
**Post date:** [October 22, 2018, 3:51am UTC](https://verificationacademy.com/forums/t/randomizing-a-sequence-item-in-hierarchical-sequences/35216/1 "2018-10-22T03:51:55Z")

</div>

I have create a Sequence Item which has few variables with rand keyword. I have sequence 1 which randomizes that sequence item and it works as expected.  
I create seq 2 which tried to randomize sequence 1 including the sequence item in the sequence 1 using inline constraints.

Now what is not working is : When i try to override sequence item in sequence 1 from sequence 2 i get randonmization failure.

// ===========================================================================  
class cM1Seq extends cM3BaseSeq;

`uvm_object_utils_begin(cM1Seq) `uvm\_object\_utils\_end

logic [31:0] Command;  
extern function new(string name = “cM1Seq”);  
extern task body();  
extern function void pre\_randomize();

endclass : cM1Seq

// ---------------------------------------------------------------------------  
// new()  
// ---------------------------------------------------------------------------  
function cM1Seq::new(string name = “cM1Seq”);  
super.new(name);

endfunction : new

* * *

// body()  
// ---------------------------------------------------------------------------  
task cM1Seq::body();  
bit [31:0] wrData[$];  
M3CmdTrn M3CmdTrn0;  
M3CmdTrn0 = M3CmdTrn::type\_id::create(“M3CmdTrn0”);  
if (!M3CmdTrn0.randomize() with {MCmdOpcode == CMD\_OPCODE\_LOAD; }) begin  
$error(“randmization failed”);  
end  
endtask : body

sequence 2:  
// ===========================================================================  
class cM2Seq extends cM3BaseSeq;

`uvm_object_utils_begin(cM2Seq) `uvm\_object\_utils\_end

logic [31:0] Command;  
extern function new(string name = “cM2Seq”);  
extern task body();  
extern function void pre\_randomize();

endclass : cM2Seq

// ---------------------------------------------------------------------------  
// new()  
// ---------------------------------------------------------------------------  
function cM2Seq::new(string name = “cM2Seq”);  
super.new(name);

endfunction : new

* * *

// body()  
// ---------------------------------------------------------------------------  
task cM2Seq::body();  
bit [31:0] wrData[$];  
cM1Seq M1Seq;  
`uvm_create(M1Seq) M1Seq.randomize() with { M3CmdTrn0.MauCmdAddr == 15'h1020;}; `uvm\_send(M1Seq)

endtask : body

Here the inline constraints from the cM2Seq is never taken effect only the cM1Seq randomization is taking effect which is in the sequence item.

---

<div class="post-metadata">

**Author:** ![chr\_sue](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/chr_sue/32/1199_2.png) [@chr\_sue](https://verificationacademy.com/forums/u/chr_sue)\
**Post date:** [October 22, 2018, 7:27am UTC](https://verificationacademy.com/forums/t/randomizing-a-sequence-item-in-hierarchical-sequences/35216/2 "2018-10-22T07:27:15Z")

</div>

_In reply to [prashanthiyer90](https://verificationacademy.com/forums/t/randomizing-a-sequence-item-in-hierarchical-sequences/35216):_

You should clean up your code first.  
For example look here:

```verilog
task cM2Seq::body();

```

you are mixing here the names.

BTW please format your code as SystemVerilog.

---

<div class="post-metadata">

**Author:** ![piyer](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/c4cdca/32.png) [@piyer](https://verificationacademy.com/forums/u/piyer)\
**Post date:** [October 22, 2018, 3:29pm UTC](https://verificationacademy.com/forums/t/randomizing-a-sequence-item-in-hierarchical-sequences/35216/3 "2018-10-22T15:29:17Z")

</div>

_In reply to [chr\_sue](https://verificationacademy.com/forums/t/randomizing-a-sequence-item-in-hierarchical-sequences/35216/2):_

Hi chr\_sue,

I have fixed the typos. Can you let me know what you meant code in system verilog?

---

<div class="post-metadata">

**Author:** ![chr\_sue](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/chr_sue/32/1199_2.png) [@chr\_sue](https://verificationacademy.com/forums/u/chr_sue)\
**Post date:** [October 22, 2018, 3:52pm UTC](https://verificationacademy.com/forums/t/randomizing-a-sequence-item-in-hierarchical-sequences/35216/4 "2018-10-22T15:52:58Z")

</div>

_In reply to [prashanthiyer90](https://verificationacademy.com/forums/t/randomizing-a-sequence-item-in-hierarchical-sequences/35216/3):_

You should format your code as SV.  
On top of entry box you see a few symbols. Select the SV code you have written and go with your mouse over the most right symbol. You’ll see a drop-down menu and select ‘SystemVerilog Code’.
