How to randomize properties of class without declaring it as rand or randc.explain with example?
class foo;
int bar;
function void randomize_bar;
void'(std::randomize(bar));
endfunction : randomize_bar
endclass : foo
module tb;
foo foo_h;
initial begin
foo_h = new;
foo_h.randomize_bar;
$finish;
end
endmodule : tb
Note that std::randomize(foo_h.bar) is not LRM compliant but some simulators might allow it with a warning.
In reply to sbellock:
If there are no other conflicting constraints in your class, you can also do
assert (foo_h.randomize(bar));