2
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?

Greg
  • 18,111
  • 5
  • 46
  • 68
  • 2
    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 Apr 26 '16 at 04:23
  • 1
    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. – Saravanan Shanmugavelu Apr 26 '16 at 05:03
  • 2
    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 Apr 26 '16 at 05:12
  • 3
    Show us exactly how you repeatedly call std::randomize 10 times. – dave_59 Apr 26 '16 at 05:42

1 Answers1

2

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

jskroch
  • 333
  • 2
  • 8
learner4
  • 76
  • 1
  • 7
  • It is more portable to use the `name` method when displaying `enum` names: `$display("Value is %s", ipv4_corrupt.name());`. Some simulators will print garbage otherwise. – toolic Apr 07 '20 at 17:55
  • Why did you replace the `enum` names with numeric values in the `dist`? One advantage of `enum` is to give meaningful names to numbers. – toolic Apr 07 '20 at 17:57