In reply to peterjin:
$urandom uses the process RNG, not the class RNG. Change $urandom to randomize and your code works.
class c_rng;
rand int i;
function void gen_print();
repeat(10)begin
void'(randomize());
$display("i=%0d",i);
end
endfunction
endclass
module test;
c_rng c1,c2;
initial begin
c1=new();
c2=new();
c2.set_randstate(c1.get_randstate());
$display("c1 generates");
c1.gen_print();
$display("c2 generates");
c2.gen_print();
end
endmodule
I prefer to use the RNG from c1 to set the RNG of c1. You don’t want to get involved managing seeds and master seeds.