typedef enum int { IPV4_VERSION = 0, IPV4_IHL = 1, IPV4_TOTAL_LENGTH = 2,IPV4_CHECKSUM = 3 } ipv4_corrupton;
ipv4_corrupton ipv4_corrupt;
std::randomize(ipv4_corrupt) with {ipv4_corrupt dist { IPV4_VERSION :=2,IPV4_IHL := 4,IPV4_TOTAL_LENGTH := 4,IPV4_CHECKSUM := 2}; };
我运行了上述代码10次,总是得到IPV4_CHECKSUM
。我犯了什么错误?
答案 0 :(得分:2)
我稍微修改了你的代码并获得了预期的输出。
module test;
typedef enum int { IPV4_VERSION = 0, IPV4_IHL = 1, IPV4_TOTAL_LENGTH = 2,IPV4_CHECKSUM = 3 } ipv4_corrupton;
ipv4_corrupton ipv4_corrupt;
initial begin
repeat(10) begin
#1
std::randomize(ipv4_corrupt) with {ipv4_corrupt dist { 0 :=2,1 := 4,2:= 4,3:= 2}; };
$display ("Value is %s",ipv4_corrupt);
end
end
endmodule
输出:
值为IPV4_VERSION
值为IPV4_IHL
值为IPV4_TOTAL_LENGTH
值为IPV4_IHL
值为IPV4_VERSION
值为IPV4_TOTAL_LENGTH
值为IPV4_CHECKSUM
值为IPV4_TOTAL_LENGTH
值为IPV4_IHL
值为IPV4_IHL