Posts

Showing posts with the label SV Constraint Scenarios

Constraint to generate 100 phone numbers, where the first three digits should be '982'

Image
  CODE:   class phone_number; rand int num[]; constraint ph_num_size {num.size() == 10;} constraint ph_num {foreach(num[i]) { (num[i]>= 0) && (num[i]<10); if(i == 0) num[i] == 9; if(i == 1) num[i] == 8; if(i == 2) num[i] == 2; } } function void display(); $write("Mobile No. is: \""); foreach(num[i]) begin $write("%0p",num[i]); end $write("\""); $write("\n"); endfunction endclass module jk; phone_number ph; initial begin ph = new(); repeat(100) begin ph.randomize(); ph.display(); //$display("size is: %0d",ph.num.size()); end end endmodule           SAMPLE OUTPUT:

System Verilog Constraint Scenario: 3

Image
   Qn. Write a constraint to generate unique random numbers between 99 to 100. SAMPLE OUTPUT:                                                                      Here's the step-by-step  video  illustration to solve this constraint. 

System Verilog Constraint Scenario: 2

Image
Qn. Write a constraint to generate the pattern 0102030405       SAMPLE OUTPUT:                                                                                             Here's the step-by-step video illustration to solve this constraint.   

System Verilog Constraints Scenario: 1

Image
 Qn. Write a constraint to generate random values divisible by 5.                     SAMPLE OUTPUT:       Here's the step-by-step video illustration to solve this constraint.