You can't override randomize

A customer asked me whether a class's randomize method could be overridden. I said I didn't know - I will find out. As is often the case, to find out I wrote a few lines of code on EDA Playground. EDA Playground is great for that, because it's always on. You don't have to queue for licences, wait for EDA tools to start, create new files, fire up editors...

So, I wrote this:

module override_randomize;
 
  class C;
    rand int i;
  endclass
 
  class E extends C;
    rand int another_i;
    function bit randomize;
      return super.randomize;
    endfunction
    function new;
      super.new;
    endfunction
  endclass
     
  initial begin
    C c = new;
    E e = new;
    void'(c.randomize); $display(c.i);
    void'(e.randomize); $display(e.another_i);
  end
 
endmodule


https://www.edaplayground.com/x/2G8z

and found out that the randomize method can't be overridden:

ERROR VCP2949 "The randomize() is a predefined method in class and cannot be overridden." "testbench.sv" 12 28
 

Comments

Popular posts from this blog

Bit Width Casting in SystemVerilog

How to convert a std_logic_vector to a hex string?

Can you add/remove more than 1 item from a queue?