Value of member class are not updated

I have the following base class:

class base_transaction extends uvm_sequence_item();

   int rand_int_list [$];   
   bit rand_bit_list [$];

   
   bit [31:0] data [$];

   //uvm_object_utils\
   `uvm_object_utils(base_transaction)

   //constructor
   function new(string name = "base_transaction");
      super.new(name);
   endfunction: new

   //add to list functions
   function void add_rand_int(ref int  mem);
      $display("array size is %d before push", rand_int_list.size());      
      rand_int_list.push_back(mem);
      $display("array size is %d after push", rand_int_list.size());
      //rand_int_list[rand_int_list.size()] = mem;
   endfunction: add_rand_int

   function void add_rand_bit(ref bit mem);
     // rand_bit_list.
      rand_bit_list[rand_bit_list.size()] = mem;      
   endfunction: add_rand_bit   
   

   //function my_randomize
   function int my_randomize(int seed);
      int temp, success;
      if (rand_int_list.size > 0)
	begin
	   for (int i = 0; i < rand_int_list.size(); i++)
	     begin
		// temp = $urandom_range(1,11);
		temp = (($urandom(seed)) + 1);
		rand_int_list[i] = temp - 1;
		success = (temp && success);
	     end
	   if(success == 0)
	     return 0;	   
	end
      if (rand_bit_list.size() > 0)
	begin
	   for (int i = 0; i < rand_bit_list.size(); i++)
	     begin
		// temp = $urandom_range(1,11);
		temp = (($urandom(seed)) + 1);
		rand_bit_list[i] = temp - 1;
		success = (temp && success);
	     end
	   if(success == 0)
	     return 0;
	   else
	     return 1;
	end
   endfunction: my_randomize
      
endclass: base_transaction
I have the following class which extend the base class:
class tx_transaction extends base_transaction;
   bit [15:0]  data_xi;
   bit [15:0]  data_xq;
   int mem_int = 2, mem_int_a = 5;  //TODO- delete

   //uvm_object_utils\
   `uvm_object_utils(tx_transaction)

   //constructor
   function new(string name = "tx_transaction");
      super.new(name);
   endfunction: new


   function void add_rand_macro();
      add_rand_int(mem_int);
      add_rand_int(mem_int_a);
   endfunction: add_rand_macro
   
   //TODO - DELETE
   function void foo();
      $display("rand mem int: %d %d", mem_int, mem_int_a);
   endfunction: foo

endclass: tx_transaction

I call the following function from the sequence (tx_trx - is tx_transaction instance, and i is iterator):

	 tx_trx.add_rand_macro();
                 tx_trx.my_randomize(i+1);
	         tx_trx.foo();

For some reason the foo function display allwas 2 5 (memt_int, mem_int_a), though those values are updated by the my_randomize function (which random the array which the member class are passed by ref)

In reply to saritr:

Hi saritr,

Consider following sample example to understand issue.
In your code “my_randomize” operates on queue list ‘rand_int_list’ but not directly on passed ref arguments [mem_int, mem_int_a].

If you want randomized values to get reflected inside your foo() method.
Option1 : Perform randomization on class objects instead using queue of int/bit type.
Option2 : Do randomization directly on [mem_int, mem_int_a] variables instead
storing them first in queue and then randomizing queue elements.

typedef class test_ext;
class tets_c;
  int a=6;  
  int int_q[$];
  test_ext test_q[$];  
    
  function add_int(ref int val);
    int_q.push_back(val);
  endfunction  
  function randomize_int();
     int_q[0]=$urandom_range(11,15);
  endfunction
  
  function add_obj(ref test_ext obj);
    test_q.push_back(obj);
  endfunction  
  function randomize_class();
    test_q[0].a=$urandom_range(21,25);
  endfunction 
endclass

class test_ext extends tets_c;
  function new() ;
    this.a=8;
  endfunction
  
  function foo();
    $display("int_q a %0d Actual a %0d",int_q[0], a);
    $display("test_q a %0d Actual a %0d",test_q[0].a,a);    
  endfunction  
endclass

  module m;
    test_ext t;    
    initial begin
      t=new();
      t.add_int(t.a);
      t.add_obj(t);
      t.foo();
      t.randomize_int();
      t.foo(); 
      t.randomize_class();
      t.foo();      
    end
  endmodule

In reply to DigvijayS:

Hey DigvijayS,
I can’t use this example because each transaction will have its own member.
For example:

class tx_transaction extends base_transaction;
   bit [15:0]  data_xi;
   bit [15:0]  data_xq;
   int mem_int = 2, mem_int_a = 5;  //TODO- delete
   .....
endclass: tx_transaction

class rx_transaction extends base_transaction;
   bit [15:0]  data_xi;
   bit xq;
   int delay =3, val = 5, num= 8;  //TODO- delete
   .....
endclass: rx_transaction

In reply to saritr:

Hi saritr,

Above example is for reference only to identify an issue.
Preferred approach to solve this will be to use In-line constraints — randomize() with,a system verilog construct !!

In reply to DigvijayS:

I can’t use In-line constraints — randomize() because I use modelSim.
The question is if there is any way to get what I want - that “my_randomize” operates on directly on passed ref arguments [mem_int, mem_int_a]…

In reply to saritr:

Saritr:

Pass by reference does not work like as you are trying to implement. Function add_rand_int(mem_int); add_rand_int(mem_int_a); scope is completed when they return. Now in queue values which you store does not pointing to mem int and mem_int_a. You need to modify the function.