Skip to content

Write post_randomize() so a queue of objects isn’t full of nulls

write-from-scratch / lifecycle-hook / array

rand Packet queue_of_pkts[$]; lets the solver pick the queue’s size, but it can’t construct the objects: new() is code, and the solver only picks values. The queue comes out the right size and full of null handles.

post_randomize() runs right after randomize() has picked every value, including the queue’s size, so it knows how many objects to build.

Fix the class below.

RequirementsFor post_randomize(), for every element of queue_of_pkts

  1. It is constructed (not null).
  2. Its own fields are randomized, not left at their defaults.

Source on GitHub

rand_queue_of_objects.sv