Turning off randomization of elements of associative array int[string]

Hi
I am observing that I cannot turn off randomization for individual elements of an associative array of int indexed by string

I have the following code


class example_cfg_obj extends uvm_object;
  `uvm_object_utils(example_cfg_obj)
   
   rand int aaInt_String[string];
   
   constraint default_c { 
       foreach(aaInt_String[sIdx]){ 
         soft aaInt_String[sIdx] == 2;
       }
   };
    
    function new(string name = "name");
      super.new(name);
       aaInt_String["x"] = 5;
       aaInt_String["y"] = 6;
    endfunction : new

    function void pre_randomize();
        string tmp;
        super.pre_randomize();
        
        //some procedural code 
        //The following statement works.i.e 
        //aaInt_String["x"] is not randomised and gets value 5
        aaInt_String["x"].rand_mode(0);        

        //The following doesnt work
        //aaInt_String["x"] is randomized and gets value of 2
        tmp = "x";
        aaInt_String[tmp].rand_mode(0); 
    endfunction : pre_randomize


endclass

Requesting some help with this behavior

Thanks
Venkatesh

In reply to Venkatesh Maddibande Sheshadrivasan:

On EDA Playground, the below code gives the results you expect for 3 of the 4 simulators. For one simulator, the behavior changes with the removal of the ‘soft’ keyword in the constraint.


import uvm_pkg::*;
`include "uvm_macros.svh"

class example_cfg_obj extends uvm_object;
  `uvm_object_utils(example_cfg_obj)
 
   rand int aaInt_String[string];
 
   constraint default_c { 
       foreach(aaInt_String[sIdx]){ 
         soft aaInt_String[sIdx] == 2;
       }
   };
 
    function new(string name = "name");
      super.new(name);
       aaInt_String["x"] = 5;
       aaInt_String["y"] = 6;
    endfunction : new
 
    function void pre_randomize();
        string tmp;
        super.pre_randomize();
 
        //The following doesnt work
        //aaInt_String["x"] is randomized and gets value of 2
        tmp = "x";
        aaInt_String[tmp].rand_mode(0); 
      aaInt_String["y"].rand_mode(0);        
    endfunction : pre_randomize
 
 
endclass
     
     module top();
       example_cfg_obj tmp_obj;
       
       initial begin
         tmp_obj = new("tmp_obj");
         tmp_obj.randomize();
         $display("X: ", tmp_obj.aaInt_String["x"]);
         $display("Y: ", tmp_obj.aaInt_String["y"]);
       end
     endmodule