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

  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:



Comments

Popular posts from this blog

Check for PALINDROME of a String using SV

System Verilog Constraint Scenario: 2