# Doubt on Scope Randomize Function

**URL:** <https://verificationacademy.com/forums/t/doubt-on-scope-randomize-function/38524>\
**Category:** SystemVerilog\
**Tags:** Doubt-on-Scope-Randomize-Function, SystemVerilog\
**Created:** [December 28, 2020, 6:04pm UTC](https://verificationacademy.com/forums/t/doubt-on-scope-randomize-function/38524 "2020-12-28T18:04:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TC\_2017](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/t/53a042/32.png) [@TC\_2017](https://verificationacademy.com/forums/u/TC_2017)\
**Post date:** [December 28, 2020, 6:04pm UTC](https://verificationacademy.com/forums/t/doubt-on-scope-randomize-function/38524/1 "2020-12-28T18:04:11Z")

</div>

```verilog

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 ::

```verilog

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 ??**

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [December 28, 2020, 10:46pm UTC](https://verificationacademy.com/forums/t/doubt-on-scope-randomize-function/38524/2 "2020-12-28T22:46:25Z")

</div>

_In reply to [TC\_2017](https://verificationacademy.com/forums/t/doubt-on-scope-randomize-function/38524):_

This is an open issue in the LRM. [0002967: define explicitly legal set of data types for randomize variables list - Accellera Mantis](https://accellera.mantishub.io/view.php?id=2967)

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

---

<div class="post-metadata">

**Author:** ![sbellock](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/f4b2a3/32.png) [@sbellock](https://verificationacademy.com/forums/u/sbellock)\
**Post date:** [December 29, 2020, 6:32pm UTC](https://verificationacademy.com/forums/t/doubt-on-scope-randomize-function/38524/3 "2020-12-29T18:32:27Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/doubt-on-scope-randomize-function/38524/2):_

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

```verilog

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.

```verilog

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

```

So much typing!

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [December 29, 2020, 6:43pm UTC](https://verificationacademy.com/forums/t/doubt-on-scope-randomize-function/38524/4 "2020-12-29T18:43:37Z")

</div>

_In reply to [sbellock](https://verificationacademy.com/forums/t/doubt-on-scope-randomize-function/38524/3):_

[https://accellera.mantishub.io/view.php?id=2970](https://accellera.mantishub.io/view.php?id=2970)

---

<div class="post-metadata">

**Author:** ![Have\_A\_Doubt](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/h/51bf81/32.png) [@Have\_A\_Doubt](https://verificationacademy.com/forums/u/Have_A_Doubt)\
**Post date:** [November 7, 2026, 4:31pm UTC](https://verificationacademy.com/forums/t/doubt-on-scope-randomize-function/38524/5 "2026-11-07T16:31:20Z")

</div>

Hi Dave,

Was trying the above code using the latest [edatools](https://edaplayground.com/x/uge5), 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](https://verificationacademy.com/forums/t/calling-randomize-with-arguments/48506) 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 ?
