Changing the seed for a class and generting different patterent for randc

Here is the example. How you can change the seed for a class and generate different pattern with randc.
If you comment the line "obj.srandom(seed)" it will generate the same pattern again after the cycle.
Try compiling it again with commenting above line.

class randctest;
randc bit [1:0] randbit;
task print;
$display("Rand C = %d", randbit);
endtask
endclass

program main;

randctest obj;

initial begin
obj = new();
for (int i=0; i<12; i++) begin
if (i % 4 == 0) begin
obj.srandom(236+i);
$display("==============");
end
if (obj.randomize()) begin
obj.print();
end
else begin
$display("Randomization failed \n");
end
end
end
endprogram : main

Output :
==============
Rand C = 0
Rand C = 1
Rand C = 2
Rand C = 3
==============
Rand C = 2
Rand C = 1
Rand C = 3
Rand C = 0
==============
Rand C = 1
Rand C = 0
Rand C = 2
Rand C = 3

Leave a Comment

"Quote of the Day"