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

**URL:** <https://verificationacademy.com/forums/t/what-is-the-difference-between-pre-randomization-and-post-randomization-methods/28266>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog\
**Created:** [December 20, 2012, 7:00am UTC](https://verificationacademy.com/forums/t/what-is-the-difference-between-pre-randomization-and-post-randomization-methods/28266 "2012-12-20T07:00:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![swamym938](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/8edcca/32.png) [@swamym938](https://verificationacademy.com/forums/u/swamym938)\
**Post date:** [December 20, 2012, 7:00am UTC](https://verificationacademy.com/forums/t/what-is-the-difference-between-pre-randomization-and-post-randomization-methods/28266/1 "2012-12-20T07:00:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mperyer](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/5f8ce5/32.png) [@mperyer](https://verificationacademy.com/forums/u/mperyer)\
**Post date:** [December 20, 2012, 9:54am UTC](https://verificationacademy.com/forums/t/what-is-the-difference-between-pre-randomization-and-post-randomization-methods/28266/2 "2012-12-20T09:54:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![swamym938](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/8edcca/32.png) [@swamym938](https://verificationacademy.com/forums/u/swamym938)\
**Post date:** [December 20, 2012, 10:13am UTC](https://verificationacademy.com/forums/t/what-is-the-difference-between-pre-randomization-and-post-randomization-methods/28266/3 "2012-12-20T10:13:10Z")

</div>

_In reply to [mperyer](https://verificationacademy.com/forums/t/what-is-the-difference-between-pre-randomization-and-post-randomization-methods/28266/2):_

thank you very much…

---

<div class="post-metadata">

**Author:** ![Rahulkumar2](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/rahulkumar2/32/3675_2.png) [@Rahulkumar2](https://verificationacademy.com/forums/u/Rahulkumar2)\
**Post date:** [December 18, 2019, 12:35pm UTC](https://verificationacademy.com/forums/t/what-is-the-difference-between-pre-randomization-and-post-randomization-methods/28266/4 "2019-12-18T12:35:21Z")

</div>

_In reply to [swamym938](https://verificationacademy.com/forums/t/what-is-the-difference-between-pre-randomization-and-post-randomization-methods/28266/3):_

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

- pre\_randomize()
- randomize
- post\_randomize()

```verilog
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
