Possible bug in randint when importing pylab?
I am getting some unexpected behavior in Python 2.6.4 on a WinXP SP3 box. If I run the following: [code] from pylab import randint for s in range(100): print randint(0,1) [/code] I get 100 zeroes. If I import randint from random instead, I get the expected behavior of a random distribution of 1s and 0s. I found this by importing * from pylab after importing randint from random. What is going on? Is pylab's randint function broken somehow? Could this be due to installing scipy into a 2.6 environment when it was designed for the 2.5 environment? cinead
Hi, 2010/8/19 Timothy Kinney <timothyjkinney@gmail.com>:
I am getting some unexpected behavior in Python 2.6.4 on a WinXP SP3 box.
This mailing list is for development *of* python, not about development *with* python. Your question should be directed to the comp.lang.python newsgroup, or the python-list mailing list. In any case, reading the documentation of both functions should answer your question. -- Amaury Forgeot d'Arc
On Thu, Aug 19, 2010 at 7:11 AM, Timothy Kinney <timothyjkinney@gmail.com> wrote:
No; this is by design. The docstring for pylab's randint says: randint(low, high=None, size=None) Return random integers from `low` (inclusive) to `high` (exclusive). IOW, it's similar to random.randrange in the stdlib. In contrast, random.randint *includes* both endpoints. It's perhaps unfortunate that random.randint and pylab.randint use different conventions, but it's not a bug. Mark
participants (4)
-
Amaury Forgeot d'Arc
-
David Cournapeau
-
Mark Dickinson
-
Timothy Kinney