← Design Verification Interviews
Interview Question · Concept
Rand Versus Randc
The Question
The interviewer asks
What is the difference between a rand and a randc variable? When would you pick randc?
You have two and a half minutes. Speak or type, then press Get Feedback under your answer. No credits needed.
Speech-to-text runs in your browser. Chrome and Edge may send audio to their own speech service.
You can edit your answer before you send it. Feedback uses AI and checks your answer only against our written answer. No credits are used and your answer is not saved.
Reveal the Model Answer
A rand variable is drawn independently on every call, so a value can repeat straight away. A randc variable is cyclic. It visits every allowed value once, in random order, before any value repeats. Then it starts a new cycle. Pick randc for a small set you want covered quickly, such as an opcode or a port number. Use rand for everything else.
randomize() call on an object with a randc field. Arrows show the solver taking and returning values. A rand field has no such list and draws from every legal value on each call.Read the diagram as text
- randomize(): called on the same object
- Values left in this cycle: stored inside the object
- Pick one at random: only from the values left
- op gets the value: no repeat until the cycle ends
- List empty: new cycle: every legal value goes back in
- randomize() → Pick one at random
- Values left in this cycle → Pick one at random: choose from
- Pick one at random → op gets the value
- Pick one at random → Values left in this cycle: remove it
- List empty: new cycle → Values left in this cycle: refill
The list lives in the object, so a new object starts a new cycle.
Self-Check
Tick each key point you covered in your answer.
What Interviewers Listen For (Fresher)
A good fresher answer states the difference: rand values can repeat, while randc values cycle. It gives a small enumerated field, such as an opcode, as the place for randc.
What Interviewers Listen For (Junior)
A good junior answer notices that the cycle belongs to one object. So a generator that builds a new object for every transaction loses the cycle.
What Interviewers Listen For (Mid-Level)
A good mid-level answer treats randc as a stimulus shortcut, not a coverage plan. It still measures opcode coverage.
Cross-Questions
Where the interviewer goes next. Open a node to practise that follow-up.
WhyBreak ItCompareScale It
- Rand Versus Randc
-
Break ItA Randc Field That Kept RepeatingL1 Junior
The opcode field is
randc, yet the log shows the same opcode twice in a row. The generator doestr = new; tr.randomize();for every transaction. Why?log gen: op=2 gen: op=2 gen: op=0 gen: op=32:30You have two and a half minutes. Speak or type, then press Get Feedback under your answer. No credits needed.
Speech-to-text runs in your browser. Chrome and Edge may send audio to their own speech service.
You can edit your answer before you send it. Feedback uses AI and checks your answer only against our written answer. No credits are used and your answer is not saved.
Reveal the Model Answer
The cycle state lives in the object, and every
newstarts a fresh cycle with its first value chosen at random. Randomize one generator object repeatedly and copy its result into each transaction, or keep therandcfield in a long-lived object.Self-Check
Tick each key point you covered in your answer.
Misconception
"
randcremembers its cycle for the whole simulation."It remembers per object. The twin constructs a new object for every call and repeats appear; one object for the whole test removes them.
Run It
A new
randcobject for every call, ten windows of four.RUNVerilator · simulator serviceExpected:FAIL: each new object starts its own randc cycle, so values repeated within four callsSee the Fix
class opcode_gen; randc bit [1:0] op; endclass module tb; opcode_gen g; int repeats = 0; initial begin g = new; // the fix: one generator object for the whole test repeat (10) begin bit [3:0] seen; seen = 0; repeat (4) begin void'(g.randomize()); seen[g.op] = 1; end if (seen != 4'hf) repeats++; end if (repeats > 0) $display("FAIL: each new object starts its own randc cycle, so values repeated within four calls"); else $display("PASS: one object kept one cycle, so every window covered all four values"); end endmodulePrints:
PASS: one object kept one cycle, so every window covered all four values -
WhyWhy Randc Fields Stay SmallL1 Junior
Why not declare a 32-bit address
randc?2:30You have two and a half minutes. Speak or type, then press Get Feedback under your answer. No credits needed.
Speech-to-text runs in your browser. Chrome and Edge may send audio to their own speech service.
You can edit your answer before you send it. Feedback uses AI and checks your answer only against our written answer. No credits are used and your answer is not saved.
Reveal the Model Answer
The solver has to remember which values of the current cycle are used, which costs memory per value of the range. So the standard lets tools limit the width of a
randcvariable, but not below 8 bits. A 32-bitrandcmay be rejected and is not portable. For addresses, a constraint plus coverage does the job.Self-Check
Tick each key point you covered in your answer.
Spec Misquote
"
randcworks on any width; it just takes longer."Tools are allowed to cap
randcwidth, and only 8 bits is guaranteed.Source IEEE 1800-2017 §18.4.2
-
WhyWhy Randc Variables Are Solved FirstL2 Mid-Level
Why are
randcvariables solved before therandvariables, and what can that break?2:30You have two and a half minutes. Speak or type, then press Get Feedback under your answer. No credits needed.
Speech-to-text runs in your browser. Chrome and Edge may send audio to their own speech service.
You can edit your answer before you send it. Feedback uses AI and checks your answer only against our written answer. No credits are used and your answer is not saved.
Reveal the Model Answer
To keep its cycle, the solver picks the
randcvalue first, from the values not yet used. Then it solves therandfields around it. If a constraint ties therandfields to that value and no solution exists, the call fails. So limiting arandcfield through other fields is fragile.Self-Check
Tick each key point you covered in your answer.
Spec Misquote
"Add
solve len before addrto order arandcfield."The standard does not allow
randcvariables insolve...before. They are always solved first.Source IEEE 1800-2017 §18.5.10
-
CompareRandc Versus Shuffling a ListL1 JuniorL2 Mid-Level
Asked if they mention covering a list of values
You must visit seven specific register addresses, in random order, exactly once each. Compare
randcwith filling an array and callingshuffle().2:30You have two and a half minutes. Speak or type, then press Get Feedback under your answer. No credits needed.
Speech-to-text runs in your browser. Chrome and Edge may send audio to their own speech service.
You can edit your answer before you send it. Feedback uses AI and checks your answer only against our written answer. No credits are used and your answer is not saved.
Reveal the Model Answer
randccycles over every value its type and constraints allow. Seven scattered addresses therefore need an index variable, a range constraint and a lookup table. An array of the seven addresses withshuffle()states the intent directly. It works for any element type and gives a new order on every call. Useshuffle()for an explicit list, andrandcwhen the set is a small contiguous range.Self-Check
Tick each key point you covered in your answer.
Misconception
"
shuffle()takes constraints likerandomize()."It is an array ordering method with no constraint support; it just permutes the elements in place.
Source IEEE 1800-2017 §7.12.2
-
Scale ItWhy Randc Is Not a Coverage StrategyL2 Mid-LevelL3 Senior
A colleague proposes making every enumerated field
randc"so coverage closes automatically". What do you tell them?2:30You have two and a half minutes. Speak or type, then press Get Feedback under your answer. No credits needed.
Speech-to-text runs in your browser. Chrome and Edge may send audio to their own speech service.
You can edit your answer before you send it. Feedback uses AI and checks your answer only against our written answer. No credits are used and your answer is not saved.
Reveal the Model Answer
randcguarantees one field's values cycle, but bugs live in combinations and sequences: opcode with length, back-to-back writes, a command during reset. Those are crosses and transitions that no per-field cycle controls. Close coverage by measuring the coverage model, finding holes and steering constraints or adding directed sequences at them.Self-Check
Tick each key point you covered in your answer.
What Interviewers Listen For (Senior)
A good senior answer moves the talk from stimulus tricks to the coverage model. It names crosses and transitions as the items that close last.
Wrong Altitude
Agrees, and adds
randcto the remaining fields.It optimises the easy part, single-field values, and leaves the cross coverage that closes late untouched.
What People Get Wrong
Common wrong answers and why they fail. Run It shows the wrong belief failing on a real simulator.
Misconception
"Four calls on a 2-bit rand field give each value once."
Each call is independent, so repeats within a window of four are the common case. The twin counts windows with a repeat; switching the field to randc makes the count zero.
Run It
Ten windows of four calls on a 2-bit rand field.
FAIL: rand draws each call independently, so values repeat within four callsSee the Fix
class opcode_gen;
randc bit [1:0] op; // the fix: randc cycles through all four values
endclass
module tb;
opcode_gen g = new;
int repeats = 0;
initial begin
repeat (10) begin // ten windows of four calls
bit [3:0] seen;
seen = 0;
repeat (4) begin void'(g.randomize()); seen[g.op] = 1; end
if (seen != 4'hf) repeats++;
end
$display("windows of four calls with a repeated value: %0d of 10", repeats);
if (repeats > 0) $display("FAIL: rand draws each call independently, so values repeat within four calls");
else $display("PASS: every window of four calls visited all four values");
end
endmodule
Prints: windows of four calls with a repeated value: 0 of 10 PASS: every window of four calls visited all four values
Half-Truth
"Use randc everywhere; it reaches coverage faster."
For wide fields a cycle is billions of calls long, and constraints between fields still decide which combinations appear. It speeds up one small field, nothing more.
Buzzword Without Mechanism
Says "randc is cyclic" but cannot say when the cycle restarts or who owns it.
The useful part is the mechanism. The object remembers which values it has used, and a new cycle starts after the last one.