What is the difference between pre randomization and post randomization methods?

what is the difference between pre randomization and post randomization methods???

When you call the randomize() method on a SV class, then the following methods are called in order:

pre_randomize()
randomize()
post_randomize()

A user can overload the pre_randomize() and post_randomize() methods but not the randomize() method. The pre-randomize() method is used to set up variables that are used in constraints during the randomize() method. The post-randomize() method is used to calculate values based on the results of the randomize() method.

In reply to mperyer:

thank you very much…

In reply to swamym938:

When you randomize the object, it go through below sequence of method execution. pre/post_randomize method are optional.

  • pre_randomize()
  • randomize
  • post_randomize()
class abc;
  rand bit [3:0]  data;
  rand bit dummy_bit;
 
  constraint c_data { data >= 3; data <= 6; }

  //display function get executed during randomization 
  constraint c_disp { dummy_bit == display(); }
 
  function void pre_randomize ();
    $display ("before randomization");
  endfunction
 
  function bit display();
    $display("during randomization");
    return 1;
  endfunction
  
  function void post_randomize ();
    $display ("after randomization");
  endfunction
endclass

program my_prg;
  
  initial begin
    abc a1;
    a1 = new();
    a1.randomize();
  end
endprogram : my_prg

before randomization

during randomization

after randomization