bit [14:0] addr_arr[3] = {15'h7ffc, 15'h7ff2, 15'h7ffb};
int msg_id = 0;
repeat(3) begin
this.pkt.randomize() with {addr == addr_arr[msg_id];};
msg_id++;
end
Now what happens is it seems that the randomized addr is incrementing only after 2 cycles.
Cycle 1: addr = 15’h7ffc
Cycle 2: addr = 15’h7ffc // It does not go to the next member of the array
Cycle 3: addr = 15’h7ff2 // The second index of the array appeared on the 3rd cycle. It should appear on the 2nd cycle
I tried that also.
Actually I put a $display before this.pkt.randomize to print if the array is properly incrementing the index and I saw that there’s no problem. But the randomization still equate the addr to the previous index.
I tried to simulate the following and found no issue.
Currently, I don’t have access to Questasim and so I ran on NC.
class packet;
rand bit [15:0] addr;
endclass
module randomize;
bit [14:0] addr_arr[3] = {15’h7ffc, 15’h7ff2, 15’h7ffb};
int msg_id = 0;
packet pkt;
initial begin
pkt = new();
repeat(3) begin
$display ("msg_id is: %0d, addr_arr[msg_id] is %0h", msg_id, addr_arr[msg_id]);
pkt.randomize() with {addr == addr_arr[msg_id];};
$display ("pkt address choosen is: %0h", pkt.addr);
msg_id++;
end
end
endmodule
Output:
msg_id is: 0, addr_arr[msg_id] is 7ffc
pkt address choosen is: 7ffc
msg_id is: 1, addr_arr[msg_id] is 7ff2
pkt address choosen is: 7ff2
msg_id is: 2, addr_arr[msg_id] is 7ffb
pkt address choosen is: 7ffb
module randomize;
bit [14:0] addr_arr[3] = {15'h7ffc, 15'h7ff2, 15'h7ffb};
int msg_id = 0;
packet pkt;
initial begin
pkt = new();
repeat(3) begin
$display ("msg_id is: %0d, addr_arr[msg_id] is %0h", msg_id, addr_arr[msg_id]);
pkt.randomize() with {addr == addr_arr[msg_id];};
$display ("pkt address choosen is: %0h", pkt.addr);
msg_id++;
end
end
Mighty be this is bug as in the repeat 3 the pkt is not created object for 3 times so it might have the object
So i think there the code should be like this
initial begin
repeat(3) begin
pkt = new();
$display ("msg_id is: %0d, addr_arr[msg_id] is %0h", msg_id, addr_arr[msg_id]);
pkt.randomize() with {addr == addr_arr[msg_id];};
$display ("pkt address choosen is: %0h", pkt.addr);
msg_id++;
end
end
yes, as part of the inline randomization, all the variable will be pointing to the class which you are randomizing. Not from the class where you are calling.