dear All,
i trying to understand the dist constraints for weighted distribution.
i thought that dist will help me in assigning equal dist (equal hits for each value) but the fact is that the total hits “approximately” equal as shown in the below histogram results. so i need to know how can i force the simulation to hit equally for each value, and how many repeats value to get that results.
code:
class Weighted;
rand int val;
constraint c_dist {val dist {1:= 1, 2:= 1, 3:= 1, 5:= 1, 8:= 1};}
endclass
module testclass;
Weighted w;
initial begin
int count[9], maxx[$];
w = new();
repeat (2000) begin
assert(w.randomize());
count[w.val]++; // Count the number of hits
end
maxx = count.max(); // Get largest value in count
// Print histogram of count
$display(count.max);
foreach(count[i])
if (count[i]) begin
$write("count[%0d]=%5d ", i, count[i]);
repeat (count[i]*40/maxx[0]) $write("*");
$display;
end
end
endmodule
results:
count[1]= 427 ****************************************
count[2]= 399 *************************************
count[3]= 391 ************************************
count[5]= 403 *************************************
count[8]= 380 ***********************************
thanks in advance.