I was recently asked an alternative to $countones( a ) == N ;
rand bit [9:0] a ;
bit [3:0] N ; // a can have Max 10 Ones !!
// constraint CCOUNTONES { $countones( a ) == N ; } // Need an Alternative for this
I came up with 2 solutions ::
(1) $countbits() Function
(2) Random helper Unpacked array and using sum() .
Is there any other Solution possible ?
Is there an alternative to sum() Constraint ?
rand bit [3:0] A [ 4 ] ;
// constraint SUM { A.sum() == 10 ; } // Any alternative to this ?