SV Constraint Question

In reply to totochan1985:


class sample;
 rand int x;
  int q[$:2];
 
 
  constraint n_sc{
    x inside {[1:10]};
    unique{x ,q};
  }
 
  function void post_randomize();
    if(q.size() != 3)
       q.push_back(x);    
    else begin 
      q.pop_front();
      q.push_back(x); 
    end   
    $display("%0d %p",x,q);
 
  endfunction
endclass
 
      module top;
 
        sample s = new();
 
        initial begin
          repeat(20) begin
            s.randomize();
            $write("%0d\n",s.x);
          end
 
        end
      endmodule

1 Like