|  | 
|  |  | 
 |  
|  |  |  |  
|  |  | 
 |  
|  |  | 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. |  
|  |  | 
 |  
|  |  | 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(). |  
|  |  | 
 |  
|  |  | 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. |  
|  |  | 
 |  
|  |  | You may overload the post_randomize() in any class to perform cleanup, print diagnostics, and check post-conditions after the object is randomized. |  
|  |  | 
 |  
|  |  |  |  
|  |  | 
 |  
|  |  | Example : pre/post randomize() |  
|  |  | 
 |  
|  |  | 
  1 class frame_t {
  2   rand bit [7:0] data;
  3   bit  parity;
  4   constraint c {
  5      data >  0;
  6   }
  7   task pre_randomize() {
  8     printf("Value of data %b and parity %b\n",data,parity);
  9   }
 10   task post_randomize() {
 11    parity = ^data;
 12   }
 13 }
 14 
 15 program pre_post_randomize {
 16    frame_t frame = new();
 17    integer i = 0;
 18    printf("-------------------------------\n");
 19    printf("Randomize Value\n");
 20    i = frame.randomize();
 21    printf("-------------------------------\n");
 22    frame.object_print();
 23    printf("-------------------------------\n");
 24 }
You could download file pre_post_randomize.vr here |  
|  |  | 
 |  
|  |  | Simulation Output : pre/post randomize() |  
|  |  | 
 |  
|  |  |  -------------------------------
 Randomize Value
 value of data xxxxxxxx and parity x
 -------------------------------
 
 "CALLING object_print":
 
     data                : hex: 06
     parity              : hex: 0
 -------------------------------
 |  
|  |  | 
 |  
|  |  | 
 |  
|  |  | 
 |  
|  |  |  |  
|  |  | 
 |  |  | 
|  
 |  
 |  
 | 
| 
 | 
|    |  
| Copyright © 1998-2025 |  
| Deepak Kumar Tala - All rights reserved |  
| Do you have any Comment? mail me at:deepak@asic-world.com
 |  |