Doubt on Scope Randomize Function


LRM  18.12  says :: 

The scope randomize function, std::randomize() , enables users to randomize data in the current
scope without the need to define a class or instantiate a class object


But the LRM isn’t clear if an object with random properties can be used as argument to it

Example ::


class seq ;

     rand bit [1:0] b ;
          
	  bit [1:0] a ;

  endclass

  seq  obj ;

  initial begin

      obj = new();

    if ( std::randomize(obj.a) with { obj.a == 3 ; } ) //  Valid ??   
      begin
         $display("Success with a == %0d",obj.a);
      end
    else
     begin
        $display("Fails");
     end

    if ( std::randomize(obj.b) with { obj.b == 2 ; } ) //  Valid ??
      begin
         $display("Success with b == %0d",obj.b);
      end
    else
     begin
        $display("Fails");
     end
  end



I see warning message on some Simulators ::

Warning: (vopt-2961) Argument #1 for std::randomize() function is non-LRM compliant.

While some throw Compilation Error ::

**if ( std::randomize(obj.a) with { obj.a == 3 ; } )

xmvlog: *E,RNDRARG : The argument to class or scope randomize must be a simple identifier of integral type.
**

[Q] Is this a violation based on LRM ??

In reply to TC_2017:

This is an open issue in the LRM. 0002967: define explicitly legal set of data types for randomize variables list - Accellera Mantis

Hopefully the IEEE P1800 committee can address this in the next revision of the standard.

In reply to dave_59:

It would also be nice to randomize an element of a struct without having the compiler yell at you.


struct
{
  int a;
  int b;
} some_struct;
  
initial begin
   void'(std::randomize (some_struct.a));
end

produces

** Warning: testbench.sv(12): (vlog-2961) Argument #1 for std::randomize() function is non-LRM compliant.

To work around you need to introduce a dummy variable.


initial begin
   int dummy_var;
    
   void'(std::randomize (dummy_var));
   some_struct.a = dummy_var;
end

So much typing!

In reply to sbellock:

https://accellera.mantishub.io/view.php?id=2970

Hi Dave,

Was trying the above code using the latest edatools, I observe that 2 of 3 tools now treat the code as legal

(1) Does 1800-2023 make any new mention about scope of std::randomize ?

Section 18.2 of 1800-2023 says

The scope randomize function behaves exactly the same as a class randomize method except that it operates on the variables of the current scope instead of class member variables

(2) So why is hierarchical referencing discussed in thread illegal for class randomize method whereas it’s legal for std::randomize ?

(3) In a module is the prefix std:: when calling the randomize function optional ?