What is the scope of randomization in SystemVerilog: which variables can…
What is the scope of randomization in SystemVerilog: which variables can be randomized, and how?
Model answer
There are two forms of randomization, and they cover different variables. Object randomization: a class property declared rand or randc is randomized by calling obj.randomize(). Constraints in the class apply. Scope randomization: std::randomize(var1, var2) randomizes variables visible in the current scope, such as module variables or local variables. They need no rand keyword, and constraints are given with an inline with clause. The rand keyword is allowed only on class properties (and on unpacked structure members). It cannot be used on a module-level or procedural variable.