[Python-bugs-list] [ python-Bugs-506647 ] random.cunifvariate() incorrect?
noreply@sourceforge.net
noreply@sourceforge.net
Tue, 14 May 2002 14:53:43 -0700
Bugs item #506647, was opened at 2002-01-21 16:19
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=506647&group_id=5470
Category: Python Library
>Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Maciej Kalisiak (abcdefghijklmno)
>Assigned to: Martin v. Löwis (loewis)
Summary: random.cunifvariate() incorrect?
Initial Comment:
random.cunifvariate() currently is defined as:
return (mean + arc * (self.random() - 0.5)) % _pi
First of all, this returns values in the range [0, pi)
due to the modulus, which really makes it a
semi-circular distribution, not circular (but I'm not a
mathie, so perhaps I'm wrong).
I think the normalizing step ("% _pi", or whatever this
gets changed to) should probably be mentioned in the
documentation for this function; it caught me by
surprise, and I expect it will catch some others too.
With this defintion, the function returns a random
value in the range [mean-arc/2, mean+arc/2). The docs
say that arc, like mean, can only be in the range
[0,pi]. This would imply that one cannot get values in
the other half of the circle, i.e. [pi, 2*pi). Since
there doesn't seem to be anything stopping the caller
from using an arc in [0,2*pi], perhaps the
documentation should be updated?
----------------------------------------------------------------------
>Comment By: Raymond Hettinger (rhettinger)
Date: 2002-05-14 16:53
Message:
Logged In: YES
user_id=80475
Martin, please approve the patch and I'll load it for Py2.3.
The docs don't match the function and the actual behavior
is weird. Thinking in degrees, calling with a mean of 175
and an arc of 20 returns {x | 0<x<5 or 165<x<180} with an
expected mean of 130 instead of the specified mean of 175.
Google reports no non-Python examples of cunifvariate so
there is no standard to match against.
The patch removes the Pi normalization in the
implementation and removes the superfluous domain
restriction in the docs.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=506647&group_id=5470