Is it possible to determine if the random member of a class was disabled using rand_mode(0)

Hi,

I am planning to build a class with some random members. I want to know if it is possible to check the randomization status of the members i.e whether their randomization has been disabled using rand_mode(0).

Following is an example:


class example_class;
   
   rand int a;
   rand int b;

   function void check_random_status();
      /* This function I intend to use for checking if a.rand_mode(0) was called */
   endfunction : check_random_status

endclass : example_class

From section 18.8 of the SV2012 LRM:

When called as a function, rand_mode() returns the current active state of the specified random variable. It
returns 1 if the variable is active (ON) and 0 if the variable is inactive (OFF).

In reply to Tudor Timi:

From section 18.8 of the SV2012 LRM:

Thanks Tudor,

Let me give you a correct example in order to understand the problem:

Consider two classes here : master class and slave class

  1. master class shall use rand_mode(0) for one of the members in slave class
  2. Question is, whether slave class shall be able to check if randomization of any one of the members is disabled

class slave_class;

   rand int a;

   function void print_status ();
         //In this method,
         //I wish to check if a.rand_mode(0) was called by master_class
   endfunction : print_status

endclass : slave_class


class master_class;

   slave_class slv;
  
   function void run();
      slv = new();
      slv.a.rand_mode(0);
      slv.print_status();
   endfunction : run

endclass : master_class


Hope the question is clear now.

In reply to desaivs1994:

You can have a code as below:

class slave_class;
 
   rand int a;
   bit status;
 
   function void print_status ();
        status = a.rand_mode();
        if(status == 0)
            $display("Random Integer A randomization is disabled");
        else if(status == 1)
            $display("Random Integer A randomization is enabled");
   endfunction : print_status
 
endclass : slave_class



In reply to Soumya Mohan:

Thank you Soumya and Tudor.