Hardware interview practice
Random dynamic arrays
Which statement about a successful randomization is correct?
Starting point
Question code
class Packet;
rand int unsigned len;
rand byte unsigned data[];
constraint c {
len inside {[1:4]};
data.size() == len;
foreach (data[i]) data[i] inside {[1:255]};
}
endclassChoose one
Answer choices
- A. data must be manually allocated before randomize or the call fails
- B. len is always chosen after all data elements because declaration order fixes solve order
- C. Only data[0] is randomized because foreach cannot use a dynamic-array size constraint
- D. The solver can choose len, size data to match, and randomize every allocated element nonzero
