Std::randomize() for classes

Hello,

I was going through the difference between obj.randmize() and std::randomize and i found this article
(std::randomize( vs. randomize( vs. this.randomize( and scope - UVM SystemVerilog Discussions - Accellera Systems Initiative Forums) and i tried following example from the same blog.



class test;  

   rand int count;
   constraint c1 { count >= 2; count <= 9; }

   function new();
      if (std::randomize(this))  // In the blog count is passed instead of this(I am checking if passing this will take constraint into account)
         $display("Count %d",count);
      if (randomize(count)) 
         $display("Count %d",count);
      if (this.randomize())
         $display("Count %d",count); 
   endfunction
endclass

I am getting following error when in try this


The argument to class or scope randomize must be a simple identifier of integral type

But I was not able to find anything related to this error in LRM.

Regards,
Saket

In reply to SAKET:

I believe there no such LRM restriction and you are seeing a “unsupported” message for an older tool version. This works on other simulators.

In your example, a simple call to randomize() would be equivalent to std::randomize(this).

In reply to SAKET:

Hi,

As per my knowledge, argument to the std::randomize() must be of integral type, you can not provide class handle to it.
With that change, it is working fine.
Please correct me if i am wrong…!!

class test;
rand int count;
constraint c1 { count >= 2; count <= 9; }

function new();
if (std::randomize(count)) // In the blog count is passed instead of this(I am checking if passing this will take constraint into account)
$display(“Count %d”,count);
if (randomize(count))
$display(“Count %d”,count);
if (this.randomize())
$display(“Count %d”,count);
endfunction
endclass

module tb_top;
test tr;
initial begin
tr = new();
end
endmodule