# Constraint on even and odd number

**URL:** <https://verificationacademy.com/forums/t/constraint-on-even-and-odd-number/39089>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, system-verilog-constraints\
**Created:** [May 18, 2021, 9:19am UTC](https://verificationacademy.com/forums/t/constraint-on-even-and-odd-number/39089 "2021-05-18T09:19:18Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![shanthi](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@shanthi](https://verificationacademy.com/forums/u/shanthi)\
**Post date:** [May 18, 2021, 9:45am UTC](https://verificationacademy.com/forums/t/constraint-on-even-and-odd-number/39089/2 "2021-05-18T09:45:58Z")

</div>

_In reply to [subbarao](https://verificationacademy.com/forums/t/constraint-on-even-and-odd-number/39089):_

```verilog

class transaction;

rand bit[15:0]array[100];

constraint C1 { foreach(array[i])
                    if(i%2==0)
                          array[i]%2 !=0;
                    else
                         array[i]%2 ==0;}
endclass

```

---

_[View the full topic](https://verificationacademy.com/forums/t/constraint-on-even-and-odd-number/39089)._
