Randomization & Constraint - Array pattern
Problem Description
Write a SystemVerilog class that randomizes a 15-element integer array such that each value from 1 to 5 appears exactly as many times as its own value, arranged in non-decreasing order. A single call to randomize() must produce exactly:1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5
Constraints / Notes
Array size is fixed at 15.
Every value must lie within
[1:5].
Example :
Expected result after randomization:
val = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5}Note: Do not use any inbuild functions like .sum() etc inside a constraint
SystemVerilog
Code Editor Access
Log in to write, run and submit your solution to this interview question. It's free.
Output
Output goes here...
