# Interview question on constraint

**URL:** <https://verificationacademy.com/forums/t/interview-question-on-constraint/39755>\
**Category:** SystemVerilog\
**Tags:** uvm-sv-constraints, SystemVerilog, constraints\
**Created:** [October 27, 2021, 5:58pm UTC](https://verificationacademy.com/forums/t/interview-question-on-constraint/39755 "2021-10-27T17:58:19Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![yourcheers](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/y/5f9b8f/32.png) [@yourcheers](https://verificationacademy.com/forums/u/yourcheers)\
**Post date:** [November 23, 2021, 4:17am UTC](https://verificationacademy.com/forums/t/interview-question-on-constraint/39755/4 "2021-11-23T04:17:37Z")

</div>

_In reply to [burra thanuja](https://verificationacademy.com/forums/t/interview-question-on-constraint/39755/3):_

There are many ways to do this, one way is to use the post randomization.

```verilog
module abc;
  
  class aa;
    rand int unsigned val[10];
 
    constraint s1 {
      foreach(val[i]){
        val[i] < 10;
        foreach(val[j]){
          if(i < 9 && j < 9 && i != j)
            val[i] != val[j];
        }
      }
    }
    
     function void post_randomize();
        val[10] = val[$urandom_range(0,8)];
     endfunction
          
  endclass

 initial begin
    aa a1 = new();
    a1.randomize();
    $display(a1.val);
  end

endmodule

```

---

_[View the full topic](https://verificationacademy.com/forums/t/interview-question-on-constraint/39755)._
