|  | 
|  |  | 
 |  
|  |  |  |  
|  |  | 
 |  
|  |  | randomize() with |  
|  |  | This construct allows the declaration of inline constraints at the point where the randomize() class method is called. These additional constraints are of the same constraint types and forms as would otherwise be declared in the randomized class.  The inline constraints are applied along with the object constraints.  The original constraints in the class definition does not have to be changed. |  
|  |  | 
 |  
|  |  | Syntax |  
|  |  | 
 |  
|  |  | inline_constraint _declaration ::=
class_variable_identifier . randomize [
   ( [ variable_identifier_list | null ] ) ]
with constraint_block
 |  
|  |  | 
 |  
|  |  | Where |  
|  |  | 
 |  
|  |  | 
  class_variable_identifier : Is the name of the instantiated object.  The unnamed constraint_block contains additional in-line constraints to be applied along with the object constraints declared in the class. |  
|  |  | 
 |  
|  |  |  |  
|  |  | 
 |  
|  |  | Example : randomize with |  
|  |  | 
 |  
|  |  | 
  1 program randomize_with;
  2   class frame_t;
  3     rand bit [7:0] src_addr;
  4     rand bit [7:0] dst_addr;
  5     constraint c {
  6       src_addr <=  127;
  7       dst_addr >=  128;
  8     }
  9     task print();
 10       begin 
 11         $write("Source      address %2x\n",src_addr);
 12         $write("Destination address %2x\n",dst_addr);
 13       end
 14     endtask  
 15   endclass
 16 
 17 
 18   initial begin
 19     frame_t frame = new();
 20     integer i = 0;
 21     $write("-------------------------------\n");
 22     $write("Randomize Value\n");
 23     i = frame.randomize();
 24     frame.print();
 25     $write("-------------------------------\n");
 26     $write("Randomize with Value\n");
 27     i = frame.randomize() with {
 28       src_addr > 100;
 29       dst_addr < 130;
 30       dst_addr > 128;
 31     };
 32     frame.print();
 33     $write("-------------------------------\n");
 34   end
 35 endprogram
You could download file randomize_with.sv here |  
|  |  | 
 |  
|  |  | Simulation Output : randomize with |  
|  |  | 
 |  
|  |  |  -------------------------------
 Randomize Value
 Source      address 02
 Destination address ab
 -------------------------------
 Randomize with Value
 Source      address 79
 Destination address 81
 -------------------------------
 |  
|  |  | 
 |  
|  |  | 
 |  
|  |  | 
 |  
|  |  |  |  
|  |  | 
 |  |  | 
|  
 |  
 |  
 | 
| 
 | 
|    |  
| Copyright © 1998-2025 |  
| Deepak Kumar Tala - All rights reserved |  
| Do you have any Comment? mail me at:deepak@asic-world.com
 |  |