# UVM randomization dilemma

**URL:** <https://verificationacademy.com/forums/t/uvm-randomization-dilemma/32785>\
**Category:** UVM\
**Tags:** Constraint-SystemVerilog, dynamic-arrays, UVM, Constraint-random-verification, constraints-for-random-variables, uvm-randomization\
**Created:** [January 26, 2017, 10:32am UTC](https://verificationacademy.com/forums/t/uvm-randomization-dilemma/32785 "2017-01-26T10:32:37Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![salmanepos](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/eb9ed0/32.png) [@salmanepos](https://verificationacademy.com/forums/u/salmanepos)\
**Post date:** [January 30, 2017, 8:38am UTC](https://verificationacademy.com/forums/t/uvm-randomization-dilemma/32785/3 "2017-01-30T08:38:35Z")

</div>

_In reply to [Tudor Timi](https://verificationacademy.com/forums/t/uvm-randomization-dilemma/32785/2):_

Hey Tudor,

Thanks for the response. Il try to shed some more light on the brackets example. Like I said, these objects (basically a collection of words) are interprated as instructions. These objects are read out from memory, the words are decoded and some action is done. So pretty much like a simple CPU. These instructions can also be looped over ( even nested). On an abstract Level, the open bracket represented the Loop start, and closed bracket Loop end. Hence the sequence of brackets must be balanced. An unbalanced sequenced would be illegal but also needs to be simulated for the error case.

So lets say there are two fields in TYPEB which control this:

TYPEB.loop\_start  
TYPEB.loop\_end

Considering an Array size of 10 lets say this is the randomized Array:  
AABBBAABBB

Now my main Problem is how to randomize the Loop\_starts and Ends across the whole Array

for example lets consider a nested Loop of depth 2

for (x…) begin  
…  
…  
for (z) begin  
…  
…  
end  
end

Heres an example of an Array corresponding to the above example.

INDEX\_\_\_\_\_TYPE\_\_\_\_\_\_LOOP\_START\_\_\_\_LOOP\_END  
0\_\_\_\_\_\_\_\_\_\_A\_\_\_\_\_\_\_\_\_NA\_\_\_\_\_\_\_\_\_\_\_\_\_NA  
1\_\_\_\_\_\_\_\_\_\_A\_\_\_\_\_\_\_\_\_NA\_\_\_\_\_\_\_\_\_\_\_\_\_NA  
2\_\_\_\_\_\_\_\_\_\_B\_\_\_\_\_\_\_\_\_\_1\_\_\_\_\_\_\_\_\_\_\_\_\_\_0 // outer Loop opening  
3\_\_\_\_\_\_\_\_\_\_B\_\_\_\_\_\_\_\_\_\_0\_\_\_\_\_\_\_\_\_\_\_\_\_\_0  
4\_\_\_\_\_\_\_\_\_\_B\_\_\_\_\_\_\_\_\_\_1\_\_\_\_\_\_\_\_\_\_\_\_\_\_0 // inner Loop opening  
5\_\_\_\_\_\_\_\_\_\_A\_\_\_\_\_\_\_\_\_NA\_\_\_\_\_\_\_\_\_\_\_\_ NA  
6\_\_\_\_\_\_\_\_\_\_A\_\_\_\_\_\_\_\_\_NA\_\_\_\_\_\_\_\_\_\_\_\_\_NA  
7\_\_\_\_\_\_\_\_\_\_B\_\_\_\_\_\_\_\_\_\_0\_\_\_\_\_\_\_\_\_\_\_\_\_\_0  
8\_\_\_\_\_\_\_\_\_\_B\_\_\_\_\_\_\_\_\_\_0\_\_\_\_\_\_\_\_\_\_\_\_\_\_1 // inner Loop closing  
9\_\_\_\_\_\_\_\_\_\_B\_\_\_\_\_\_\_\_\_\_0\_\_\_\_\_\_\_\_\_\_\_\_\_\_1 // outer Loop closing

Like you already wrote its pretty easy to create an Array of size n with objects of TPYE A or B. The tough part for me is to write the constraints that properly sets the Loop\_start/ end fields.

Im guessing i Need to add some helper variables ( higher layer) e.g int nested depth.  
if nested depth is 0 that would mean (). The constraints for the Loop\_start/end variables  
should set Loop\_start(1),Loop\_end(0) for some TYPE B object and for a later TYPEB one the values should be Loop\_start(0),Loop\_end(1)

I hope the Problem im facing is clear now. Thanks again

---

_[View the full topic](https://verificationacademy.com/forums/t/uvm-randomization-dilemma/32785)._
