1. Simple Weighting
A weighted distribution randomly generates a value (within a predetermined range) a specified percentage of the time. DistInt is a weighted distribution that specifies a weight and uses the corresponding index value of the weight as the value to be selected for randomization. Hence, the input to DistInt is an integer_vector of weights. The return value is the index of the selected weight. For a literal value, it will return a value from 0 to N-1 where N is the number of weights specified. The frequency that each value will occur is weight/(sum of weights). As a result, in the following call to DistInt the likelihood of a 1 to occur is 7/10 times or 70%. The likelihood of 3 is 20% and 5 is 10%.
variable RV : RandomPType ; variable DataInt1, DataInt2 : integer ; . . . DataInt1 := RV.DistInt( (7, 2, 1) ) ;
Weighted distributions also support an exclude vector. The following code excludes the last value generated:
. . . DataInt2 := RV.DistInt( (1, 2, 4, 8, 16, 32), (1 => DataInt2)) ;
2. Weights plus Values
DistIntVal allows the specification of a value and a weight. DistValInt is called with an array of value pairs. The first item in the pair is the value and the second is the weight. The frequency that each value will occur is weight/(sum of weights). As a result, in the following call to DistValInt, the likelihood of a 0 is 70%, 1 is 20% and 2 is 10%.
variable RV : RandomPType ; variable DataInt1, DataInt2 : integer ; . . . -- Generate 1 70%, 3 20%, and 5 10% of the time DataInt1 := RV.DistValInt( ((1, 7), (3, 2), (5, 1)) ) ; . . . -- Generate 1, 3, 5, 7 each 25% of the time and skip the previously generated value. DataInt2 := RV.DistValInt( ((1, 25), (3, 25), (5, 25), (7, 25)), (1 => DataInt2) ) ;