Randc variable randomization inside top sequence class

I have the following code in which data act as top sequence which execute other sequences and I am using this offset to pass it to another child sequence

class Data ;
  randc bit [1:0] offset ;
   
  virtual task body () ;
    for (int i=0; i<4 i++) begin
      this.randomize ();
      $display ("value of offset=%0b",offset);
      "executing another sequence which take offset as an input " 
    end
  endtask
endclass

the problem is that this offset output is not randomized as cyclic at all , some values are repeated without providing all values for offset.

I feel its related to case of double randomization of same variable. I feel you randomize the data sequence in testcase, then offset is randomized cyclic way and when you call start(), then body () is being executed after that.
Again, there is this.randomize() inside body() task. So, remove this.randomize() call to see the correct result

@Sabarish, that should not matter. offset should remain cyclic within the for` loop.

The code shown works for me (see below). There is probably something wrong with the code you did not show.

class Data ;
  randc bit [1:0] offset ;
   
  virtual task body () ;
     for (int i=0; i<4;i++) begin
      this.randomize ();
      $display ("value of offset=%b",offset);
    end
  endtask
endclass

module top;
  
  Data d=new;
  initial d.body();
endmodule
1 Like

Thanks Dave! You are right!