New submission from Edward Preble <preble.edw...@gmail.com>:

The random.triangular function produces an unexpected distribution result 
(instead of an error or warning message) when the order of the 3 arguments are 
mixed up.

Python notebook with demo of issue here:
https://github.com/epreble/random_triangular_distribution_issue

Cases 1-4 are OK
1. random.triangular(low, high, mode) (Docs specified usage)
2. random.triangular(high, low, mode)
3. random.triangular(low, high)
4. random.triangular(high, low)

Incorrect argument input (e.g. numpy style) yields distributions that are NOT 
3-value-triangular and the output is also from different ranges than expected:

Incorrect arguments (first one is numpy.random.triangular style)
6. random.triangular(low, mode, high) 
or:
7. random.triangular(high, mode, low)

Raising errors was discouraged in prior discussion 
(https://bugs.python.org/issue13355) due to back compatibility concerns. 
However, I would argue that output of an incorrect distribution without a 
warning is a problem that -should- be broken, even in old code.

A possible solution, that might not break the old code (I haven't looked at all 
the edge cases):

If 3 arguments provided, need to be sure the mode is arg3:
If arg1 < arg2 < arg3, this is definitely wrong since the mode is definitely in 
the middle (wrong position).
If arg1 > arg2 > arg3, this is definitely wrong since the mode is definitely in 
the middle (wrong position).

Those tests would not break the old use cases, since the signs of the tests 
switch between arg1/arg2/arg3:
  low, high, mode (would be arg1 < arg2 > arg3)
  high, low, mode (would be arg1 > arg2 < arg3)

Not positive how all the <=, >= combos work out with these tests.

----------
components: Library (Lib)
messages: 311377
nosy: eddieprebs
priority: normal
severity: normal
status: open
title: random.triangular yields unexpected distribution when args mixed
type: behavior
versions: Python 2.7, Python 3.6

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32736>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to