Skip to question
ASIC.FYI
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
ASIC.FYI/Interview questions/Randomize free-range allocation

Q276·Free·Design Verification

Randomize free-range allocation

Difficulty
Medium
Topic
Memory Systems
Language
SV
Interview prompt

Question

Allocate from a randomly selected sufficient free range, then choose a valid random start within that range.

Starting point

Question code

function bit alloc_random(
  int unsigned size,
  output int unsigned addr
);
Reviewed example

Trace one case

Input
free=[[0x1000,0x10FF],[0x2000,0x20FF]]; request size=0x40
Expected output
One valid randomized result: base=0x2040; remaining selected-range fragments=[[0x2000,0x203F],[0x2080,0x20FF]]

Either free range and several starts are legal. This result demonstrates preservation of both prefix and suffix, so it is not the only valid random outcome.

What to cover

Requirements

  1. Choose uniformly among eligible ranges.
  2. Choose a valid start in the selected range.
  3. Preserve both unused prefix and suffix fragments.
  4. Return 0 without mutating state when no range is sufficient.
Exact question handoffPractice Q276

Solve it in the question bank, keep your progress, and reveal the reviewed solution when your access allows.

Open in question bank →
Solution accessA Free account unlocks the complete reviewed solution.
Continue learning

Design Verification

  • Memory Systems
  • Allocator
  • Randomization
  • Interval splitting
SystemVerilog constraints questions →
Continue practicing

Related questions

Q212 · Memory SystemsBuild a first-fit range allocator→Q262 · Memory SystemsAllocate on a power-of-two boundary→Q290 · Memory SystemsImplement best-fit allocation→
ASIC.FYI · Learn silicon end to end.info@asic.fyi