quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif pre/post randomize()

Every class contains built-in pre_randomize() and post_randomize() tasks, that are automatically called by randomize() before and after it computes new random values.

   

space.gif

Syntax

   

space.gif

function void pre_randomize();
function void post_randomize();
   

space.gif

When obj.randomize() is invoked, it first invokes pre_randomize() on obj and also all of its random object members that are enabled. Pre_randomize() then recursively calls super.pre_randomize().

   

space.gif

Post_randomize() then recursively calls super.post_randomize(). You may overload the pre_randomize() in any class to perform initialization and set pre-conditions before the object is randomized.

   

space.gif

You may overload the post_randomize() in any class to perform cleanup, print diagnostics, and check post-conditions after the object is randomized.

   

space.gif

   

space.gif

  ../images/main/4blue_dots_bullets.gif Example : pre/post randomize()
   

space.gif


  1 program pre_post_randomize;
  2 
  3   class frame_t;
  4     rand bit [7:0] data;
  5     bit  parity;
  6     constraint c {
  7      data >  0;
  8     }
  9     function void pre_randomize();
 10       begin
 11         $write("pre_randomize  : Value of data %b and parity %b\n",data,parity);
 12       end
 13     endfunction
 14     function void post_randomize();
 15       begin
 16         parity = ^data;
 17         $write("post_randomize : Value of data %b and parity %b\n",data,parity);
 18       end
 19     endfunction
 20    endclass
 21 
 22   initial begin
 23     frame_t frame = new();
 24     integer i = 0;
 25     $write("-------------------------------\n");
 26     $write("Randomize Value\n");
 27     $write("-------------------------------\n");
 28     i = frame.randomize();
 29     $write("-------------------------------\n");
 30   end
 31 endprogram
You could download file pre_post_randomize.sv here
   

space.gif

  ../images/main/4blue_dots_bullets.gif Simulation Output : pre/post randomize()
   

space.gif

 -------------------------------
 Randomize Value
 -------------------------------
 pre_randomize  : Value of data 00000000 and parity 0
 post_randomize : Value of data 00000110 and parity 0
 -------------------------------
   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright © 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com