DescriptionQ527
Q527DVASIC interview problem
Constrain exactly K set bits
TechniquesRandomization$countonesBit mask
DifficultyEasy
TopicConstraints
LanguageSystemVerilog
Requirements3 checkpoints
01
Problem
Use $countones to randomize a W-bit mask containing exactly K set bits.
Example input and output
Use this case to check your interpretationInput
W=8, K=3Output
One valid randomized result: mask=8'b0010_1010Explanation
The result contains exactly three one-bits; any other 8-bit value with popcount three is equally valid unless additional weights apply.
02
Requirements (3)
- Keep W and K compile-time configurable.
- Use a two-state randomized mask.
- Treat K outside 0 through W as an unsatisfiable configuration.
