2
votes
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}; };

I ran the above code 10 times and always got IPV4_CHECKSUM. I am making any mistake?

1
are you repeating the same randomization in the same simulation, or running different simulations each with a single randomization? The first should get you random values. The second will be determent by the seed from command line. I believe the default seed is 1. Refer to your manual on how to set the seed; the option is usually -seed, -svseed, or -rseed, again it is tool specific so check the manual. Typically the value can be a 32-bit signed value, or the word rand or random which will use pseudo random value from your OS. - Greg
Yes i am calling the above randomization in same simulation 10 times. I am always running a simulation wi different seed. But still i see same value getting generated. - user3510047
Hello, I tried to run your piece of code and its working fine.I didn't see any issue with this code.Its give random value of enum type variable.So, I suggest you to check it ones and try to more explore it or attached some result regarding this. - ChetanJoshi
Show us exactly how you repeatedly call std::randomize 10 times. - dave_59

1 Answers

2
votes

I modified your code a bit and got the expected output.

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

Output:

Value is IPV4_VERSION

Value is IPV4_IHL

Value is IPV4_TOTAL_LENGTH

Value is IPV4_IHL

Value is IPV4_VERSION

Value is IPV4_TOTAL_LENGTH

Value is IPV4_CHECKSUM

Value is IPV4_TOTAL_LENGTH

Value is IPV4_IHL

Value is IPV4_IHL