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

<div class="post-metadata">

**Author:** ![rag123](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/eada6e/32.png) [@rag123](https://verificationacademy.com/forums/u/rag123)\
**Post date:** [February 5, 2019, 5:01am UTC](https://verificationacademy.com/forums/t/constraint-for-one-hot-encoded-vectors-in-sv/35476/8 "2019-02-05T05:01:39Z")

</div>

Hi Dave,

I ran the program and i am getting compile Error. Can you help?

module top;  
class A;  
randc bit [24:0] vector;  
constraint one\_hot { $countones(vector) == 1; }  
endclass

A h;

initial begin  
h = new;  
repeat (25) begin  
assert (h.randomize());  
$displayb(h.vector);  
end  
end  
endmodule

rror-[IVCB-NORANDC] Illegal use of randc variable  
design.sv, 5  
top, “this.vector”  
The expression contains the variable vector of type randc and cannot be used  
in solve-before, distribution, unique and function calls.  
Change the type of the randc variable or remove it from the expression.

---

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