views:

34

answers:

1

This is for SystemVerilog. I know you can specify weights for values, or ranges of values, in the set of values that a random variable chooses from, but what if you want a nice Gaussian distribution? How do you write that kind of constraint?

A: 

When randomize is called, this class will generate values for variable "value" with a normal (Gaussian) distribution whose mean and standard deviation are 100 and 20, respectively. I haven't tested this much but it should work.

class C;

  int seed = 1;
  rand int mean;
  rand int std_deviation;
  rand int value;

  function int gaussian_dist();
    return $dist_normal( seed, mean, std_deviation );
  endfunction

  constraint c_parameters {
    mean == 100;
    std_deviation == 20;
  }

  constraint c_value { value == gaussian_dist(); }

endclass
Steve K