Hardware interview practice
Bias burst lengths by range
Randomize a burst length from 1 through 16 so lengths 1-4 collectively occur 70% of the time and lengths 5-16 collectively occur 30%.
Reviewed example
Work through one case
Input
randomize burst_len in 1..16 with [1:4] :/ 70 and [5:16] :/ 30Expected output
One legal randomized result: burst_len=4The :/ operator distributes each bucket's total weight across its members. A draw of 4 is legal; repeated trials approach the intended 70/30 bucket split, but one solve is non-unique.
What to cover
Requirements
- Every value from 1 through 16 must remain legal.
- Apply weights to each range as a whole.
- Do not accidentally give every member of a range the full range weight.
