Constraint Randomization Interview Question

In reply to Ammu786:

module test;
class gen;
       bit [31:0] pattern = 32'hFFFF_FC00;
  rand bit [31:0] value;
  rand bit [4:0]  rotate;
  constraint c { value == (pattern << rotate | pattern >> 32-rotate);  } // circular rotate
endclass
  gen h =new;
  initial repeat (10) begin
    assert(h.randomize());
    $display("%2d %b", h.rotate, h.value);
  end
endmodule

Depending on your definition of “consecutive” you may want to limit rotate < 23.
[br]
In reply to Have_A_Doubt:
Because sometimes v[i+:10] is out of range.

1 Like