Randomization and Constraints - Multiple of 4
Problem Description
Randomize a array such that the number is a multiple of 4, within the range 0 to 20 (inclusive), in strictly ascending order — resulting in exactly 0, 4, 8, 12, 16, 20
Following is the input array :
rand int val[6];After randomization, the array should look like below :
val = {0, 4, 8, 12, 16, 20};
Constraints / Notes
All 6 values must be multiples of 4.
Every value must lie within
[0:20].Values must be strictly ascending.
For this range and step size, exactly one valid solution exists — the result must always be
{0, 4, 8, 12, 16, 20}.
SystemVerilog
Code Editor Access
Log in to write, run and submit your solution to this interview question. It's free.
Output
Output goes here...
