Hi All,
I would like to generate gray code pattern:
0 1 3 2 6 7 5 4
I have tried with the following code, but could not get the above pattern, please suggest.
module p1;
class c1;
rand bit [2:0] gray;
bit [2:0] res;
function void post_randomize();
foreach (gray[k]) begin
gray[2] = gray[2];
gray[1] = gray[1] ^ gray[2];
gray[0] = gray[0] ^ gray[1];
end
res = {gray[2], gray[1], gray[0]};
$display("gray output %0d", res);
endfunction
endclass
c1 obj;
initial begin
obj = new;
repeat (8)
obj.randomize();
end
endmodule
Thank You,