How to call post_randomize

Hi ,

I have a data item class.
I am using create method and new to create the item class object.
I have a function post_randomize inside this class.
However it doesnt get called by default.
Is it because I am using create and not new for generating the data item class?

regards,
Nipoon

The create method eventually calls new, so that should not matter.

obj_h.post_randomize() is called implicitly when you call obj_h.randomize(). post_randomize() is also called for any object that is a random variable of the object you called randomize() on. For example

class A;
  rand int i;
  function void post_randomize();
    $display(i);
  endfunction
endclass
class B;
  rand A a;
endclass

B b;

Before you call b.randomize(), b.a must already be constructed to randomize b.a.i and then call b.a.post_randomize().

Mayebe your randomize() call failed due to conflicting constraints? Remember that post_randomize is called only when the randomize() is successful.

Ajeetha, CVC

Had the same problem. The cause was a classic one. Forgot to call super.post_randomize() in a derivative class’s post_randomize function.