SystemVerilog OOP Mastery · All levels

Randomization with Constraints: Exercises

Exercises for Randomization with Constraints.

Practice exercises

Exercise 1

Create constraints so addr is 4-byte aligned and in range 0 to 255, then randomize only writes in one test.

Solution

diagram
Class constraints: addr inside {[0:255]}; addr % 4 == 0;. Test call: obj.randomize() with { write == 1; }; and check return value.

Exercise 2

Your randomize call fails after adding with { burst_len > 12; } to class where burst_len <= 12. What is the fix?

Solution

diagram
Remove or relax the conflicting inline condition. Inline with cannot violate hard class constraints unless class constraints are changed.

Related topics