# Constraint for one hot encoded vectors in SV

**URL:** <https://verificationacademy.com/forums/t/constraint-for-one-hot-encoded-vectors-in-sv/35476>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog\
**Created:** [December 17, 2018, 5:38pm UTC](https://verificationacademy.com/forums/t/constraint-for-one-hot-encoded-vectors-in-sv/35476 "2018-12-17T17:38:33Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![sriram.seshagiri](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@sriram.seshagiri](https://verificationacademy.com/forums/u/sriram.seshagiri)\
**Post date:** [March 7, 2019, 4:16am UTC](https://verificationacademy.com/forums/t/constraint-for-one-hot-encoded-vectors-in-sv/35476/15 "2019-03-07T04:16:55Z")

</div>

Hi Dave,

I tried to this using a dynamic array but, it is not working for me. IN EDA playground it is timing out. Not sure if there is any issue in my constraint. I should try this probably in my work place environment and, see as well.

This is getting timed out after a min or 2. Is this some stack mem limitation of EDA Tools that is using Synopsys VCS 2014.

```verilog
module top;
  class A;
    rand bit [24:0] vector[];
    constraint one_hot {
       vector.size() == 25;
      foreach(vector[i])
        $countones(vector[i]) == 1;
    }
    
    constraint c_uniq {
        unique {vector};
       
    }
    
  endclass
 
  //A h;
module top ();
  initial begin
    A h = new;
    //repeat (25) begin
       assert (h.randomize());
       $displayb(h.vector);
    //end
  end
endmodule

```

---

_[View the full topic](https://verificationacademy.com/forums/t/constraint-for-one-hot-encoded-vectors-in-sv/35476)._
