Constraint Randomization Interview Question

In reply to ben@SystemVerilog.us:
It was pointed ot on LinkedIn that “This would fail if int1 is greater than 22. Ex: if int1 is 25, would int2 become 34 or it would wrap around and have the value 2?”
Changing the Low bound constraint for int1 fixes this.

int1 is 22 , int2 is 31

c1.v= 00000000001111111111111111111111


class c; 
  rand bit[31:0] v;  
  rand int int1 , int2 ;
  constraint  LOW_BOUND     {  int1  inside { [ 0 : 22 ] } ; }
  constraint  UPPER_BOUND   {  int2  inside { [ 0 : 31 ] } ; }
  constraint  DIFF          {  int2 ==  int1  +  9 ;  } 
  // constraint ct12 { $countones(v) == ( 32 - 10 ) ; }  // Can be Skipped  !!
  constraint  VAL  {     foreach( v[i] )
                        { 
                          if( i inside {[int1:int2] } ) 
                            v[ i ] == 0 ;
                          else
                            v[ i ] == 1 ;
                        }
                   }
    function  void  post_randomize() ;
    $display(" int1  is  %0d , int2 is %0d" , int1 , int2) ;
    endfunction
endclass