Problem with parameterized Defines

Please go through below code

class seq_lib extends uvm_sequence;

  first_seq     seq_1;
  second_seq    seq_2;
  third_seq     seq_3;
......so on.............
  tenth_seq     seq_10;


  `define RAND_SEQ(seq_num) `uvm_do(seq_``seq_num)


  task random_sequence;
     int rand_seq;
     rand_seq = $urandom_range(10,1);
     `RAND_SEQ(rand_seq);
  endtask

endclass

I want to randomly select a sequence from 10 defines sequences and run using uvm_do();
uvm_do(seq_1),uvm_do(seq_9)…etc when run with different seed

To achieve this i have used a define With the above code, RAND_SEQ(rand_seq) will be preprocessed and gives error that “seq_rand_seq is undefined identifier” at `define

If i write as below,
if(rand_seq == 1) RAND_SEQ(1) else if(rand_seq == 2) RAND_SEQ(2)
else if()…

I need to write for all 10 sequences
then only it works.

If i have 100 sequences, i can’t do the same for 100.

How can i achieve above requirement in a simple way.

In reply to swathi allenki:

Compiler directives are pre-processor stuff and hence can’t be used in the way you are looking for. UVM library already has this feature for you - it is called uvm_sequence_library, use that.

Regards
Srini
www.go2uvm.org

In reply to swathi allenki:
You can do this with a simple array of uvm_object_wrappers

uvm_object_wrapper seq_array[$];

// in the constructor or the body of some other method
  seq_array.push_back(first_seq::get_type());
  seq_array.push_back(second_seq::get_type());
  seq_array.push_back(third_seq::get_type());
  ...
  seq_array.push_back(tenth_seq::get_type());

 task random_sequence;
     uvm_sequence#(your_item_type) seq;
     int rand_seq;
     rand_seq = $urandom_range(9,0);
     $cast(seq,seq_array[rand_seq].create_object(""));
     seq.start();
 endtask

In reply to dave_59:

Hi dave,

when i did using array,

near
$cast(seq,seq_array[rand_seq].create_object(“”)); in random_sequence task,
following error is seen

here rand_seq = 2

 $cast(seq,seq_array[rand_seq].create_object(""));
     |

ncsim: *E,BCLCST : Invalid cast: a value with the class datatype ‘umc_pkg::third_seq’ cannot be assigned to a class variable with the datatype ‘uvm_pkg::uvm_sequence#(uvm_sequence_item,uvm_sequence_item)’.
ncsim: *E,TRNULLID: NULL pointer dereference.

Near cast() error is seen. what has to be done?

In reply to swathi allenki:
I forgot to parameter seq with the transaction type in my example.

uvm_sequence#(your_item_type) seq;