How to contrain the number of "1" of a bit-sequence in Systemverilog

Status
Not open for further replies.

weben

Newbie level 5
Joined
May 17, 2011
Messages
8
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Visit site
Activity points
1,349
In my systemverilog testbench, I need to genrate a 32 bits sequence which randomly contains 5 to 27 bit "1". Can anyone help me to describe the constrant of this random bit-sequence? thanks a lot
 

Thanks Dave,
It's really helpful. But $countones seems only works in Questa. VCS does not support using $contones in contstraint blocks in 2012.09 version.
 

You can try

Code:
rand bit value[31:0];
constraint random_bit_sequence {value.sum() with (int'(item)) inside {[5:27]}; }
 
Reactions: weben

    weben

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…