# 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:** 2

<div class="post-metadata">

**Author:** ![sbellock](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/f4b2a3/32.png) [@sbellock](https://verificationacademy.com/forums/u/sbellock)\
**Post date:** [December 17, 2018, 5:47pm UTC](https://verificationacademy.com/forums/t/constraint-for-one-hot-encoded-vectors-in-sv/35476/2 "2018-12-17T17:47:54Z")

</div>

_In reply to [Gokul S](https://verificationacademy.com/forums/t/constraint-for-one-hot-encoded-vectors-in-sv/35476):_

You can use the $countones system function.

```verilog

std::randomize (some_var) with {$countones(some_var) == 1;};

```

---

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