Interview question on constraint

In reply to burra thanuja:

Can anyone plz help me with this constraint question…
Take a rand variable with array size 10,need to get unique values in each location without using unique keyword and for any of 2 locations we need to get same value?


module abc;
  class aa;
    rand int unsigned val[10];
    rand int unsigned r_index1,r_index2;

    constraint s1 {
      r_index1 == inside {[0:9]};
      r_index2 == inside {[0:9]};
      r_index1 != r_index2;

      foreach(val[i]){ val[i] < 10; }

      foreach(val[i]){
        foreach(val[j]){
          if(i != j && i!=r_index1  && j!=r_index1)
            val[i] != val[j];
        }
      }

      val[r_index1] == val[r_index2];
    }	
  endclass
 
  initial begin
    aa a1 = new();
    a1.randomize();
    $display(a1.r_index1, a1.r_index2);
    $display(a1.val);
  end
endmodule