Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Random dynamic arrays

Hardware interview practice

Random dynamic arrays

MediumConstraintsSystemVerilog

Which statement about a successful randomization is correct?

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
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]};
  }
endclass
Choose one

Answer choices

  1. A. data must be manually allocated before randomize or the call fails
  2. B. len is always chosen after all data elements because declaration order fixes solve order
  3. C. Only data[0] is randomized because foreach cannot use a dynamic-array size constraint
  4. D. The solver can choose len, size data to match, and randomize every allocated element nonzero
Continue practicing

Related questions

ConstraintsSolve before→ConstraintsRand_mode→
asic.fyi · Learn silicon end to end.info@asic.fyi