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.
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 ?
(1)(2) This is an oversight in the BNF syntax description, which resulted in unintended consequences. We didn’t get around to correcting it in the 1800-2023 standard, even though some simulators had supported it as intended for a while.
You don’t need to use the prefix std:: since the std package is automatically imported. The only place it’s needed is within a class method to distinguish it from the built-in randomize() class method.
Just wanted to confirm if I have been able to follow the above conversation
Section 18.7 uses variable_identifier_list for randomize()
(A) Referencing variables hierarchically is illegal for variable_identifier_list whereas variable_lvalue_list could reference variables hierarchically
Is my understanding correct ?
(B) Would this also mean that there should be an update in following quote from 18.12 ?
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
Unlike class randomize function, scope randomize function allows hierarchical referencing.
So they are not exactly the same in terms of the argument
(B) It’s also correct, but I would reverse the restrictions. The arguments to the class’s randomize() method are limited to its member class variables, while the scope std::randomize() method can include any variables.