Reply To: Negative weights and index range in DistInt(weights)?

Why OSVVM™? Forums OSVVM Negative weights and index range in DistInt(weights)? Reply To: Negative weights and index range in DistInt(weights)?

#429
Jim Lewis
Member

Hi Andy,

Yikes!

Above, you have identified two issues:

  1) Handling negative weights, is it fatal or are we tolerant [treat  as 0].

  2) Always return values in the range of 0 to n-1, silently returning integer’left is bad.

WRT issue 1,  it would be easy to treat negative weights as either a zero or a severity failure.   FAILURE is consistent with other errors in the package, such as DistInt with all weights as 0 or in RandInt with a minimum value that is greater than maximum value. 

How did you end up with negative weights?  Programming error or normal algorithm behavior?  

OTOH, if negative weights are not a severity failure, then should all 0’s be a severity failure? If all 0’s occurs, it could issue an error level assert and return a value in the range 0 to n-1. Personally, I prefer failures.  However, if an algorithm is generating negative weights, I am not against the DistInt changing them to 0.  Any opinions?

WRT issue 2, the final return will be changed to have an report… failure prior to it. Without negative weights, the program will not reach this point.  However, it would be bad if something unexpected caused a similar problem.  With the severity failure, it would also be prudent to change the value to a value in the expected range.