# Extending Class Problem

**URL:** <https://verificationacademy.com/forums/t/extending-class-problem/29241>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, Extended-Class\
**Created:** [March 11, 2014, 12:18pm UTC](https://verificationacademy.com/forums/t/extending-class-problem/29241 "2014-03-11T12:18:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hvgbl](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/h/9de053/32.png) [@hvgbl](https://verificationacademy.com/forums/u/hvgbl)\
**Post date:** [March 11, 2014, 12:18pm UTC](https://verificationacademy.com/forums/t/extending-class-problem/29241/1 "2014-03-11T12:18:45Z")

</div>

Hello all,  
Sorry for silly question.

I want to give constraints to my address fields in TEST FILE.  
and the address fields are defined in PACKET CLASS.

I done “class packet\_cwdt extends packet;”  
and in that class, i have defined a new field, which is address and giving constraints to that field.  
Now, i have to randomize my whole transaction, with respect to this constrained address fields.  
How can i do it ?  
can any one please suggest something ?

## i have assigned like this. “e1.gen.p2rand.add=pkt\_cwdt.add;” e1-\> env class object gen-\> generator class object p2rand-\> obj of packet class, which is to be randomize. add-\> field of packet class.

pkt\_cwdt-\> object of constrained packet class.  
add-\> field of constrained packet class.

---

<div class="post-metadata">

**Author:** ![cgales](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/c/ccd318/32.png) [@cgales](https://verificationacademy.com/forums/u/cgales)\
**Post date:** [March 11, 2014, 1:02pm UTC](https://verificationacademy.com/forums/t/extending-class-problem/29241/2 "2014-03-11T13:02:05Z")

</div>

It is hard to understand what you are trying to accomplish based upon what you have provided. Can you post your code along with any relevant log files?

In order to be able to randomize any class variable, you need to make sure that the keyword ‘rand’ is part of the variable declaration. Then, after the class is new’ed, you can call the randomize() function on that class. Any defined constraints will be utilized when randomizing the class variables, and there are several different techniques to change this behavior.
