Re: random.randint() slow, esp in Python 3

2011-09-24 Thread Mark Dickinson
On Sep 24, 10:38 am, Ian Kelly wrote: > On Sat, Sep 24, 2011 at 12:55 AM, Steven D'Aprano > > > > > > > > > > wrote: > > If you want unbiased, random (or at least pseudo-random) integers chosen > > from an uniform distribution with proper error checking, you should use > > randint or randrange. >

Re: random.randint() slow, esp in Python 3

2011-09-24 Thread Chris Angelico
On Sat, Sep 24, 2011 at 4:55 PM, Steven D'Aprano wrote: > Chris Angelico wrote: > > If you want unbiased, random (or at least pseudo-random) integers chosen > from an uniform distribution with proper error checking, you should use > randint or randrange. > > "I only need random-ish ints, but I nee

Re: random.randint() slow, esp in Python 3

2011-09-24 Thread Ian Kelly
On Sat, Sep 24, 2011 at 12:55 AM, Steven D'Aprano wrote: > If you want unbiased, random (or at least pseudo-random) integers chosen > from an uniform distribution with proper error checking, you should use > randint or randrange. > > >> but if you just >> want a pile of more-or-less random integer

Re: random.randint() slow, esp in Python 3

2011-09-24 Thread Steven D'Aprano
Chris Angelico wrote: > On Fri, Sep 23, 2011 at 4:14 AM, Steven D'Aprano > wrote: >> What makes you think it's in C? I don't have Python 3.3a, but in 3.2 the >> random module is mostly Python. There is an import of _random, which >> presumably is in C, but it doesn't have a randint method: > > T

Re: random.randint() slow, esp in Python 3

2011-09-22 Thread Chris Angelico
On Fri, Sep 23, 2011 at 4:14 AM, Steven D'Aprano wrote: > What makes you think it's in C? I don't have Python 3.3a, but in 3.2 the > random module is mostly Python. There is an import of _random, which > presumably is in C, but it doesn't have a randint method: True. It seems to be defined in cpy

Re: random.randint() slow, esp in Python 3

2011-09-22 Thread Steven D'Aprano
Chris Angelico wrote: > The standard library function random.randint() seems to be quite slow > compared to random.random(), and worse in Python 3 than Python 2 [...] > But this still doesn't explain why randint() is so much slower. In > theory, randint() should be doing basically the same thing t

random.randint() slow, esp in Python 3

2011-09-22 Thread Chris Angelico
The standard library function random.randint() seems to be quite slow compared to random.random(), and worse in Python 3 than Python 2 (specifically that's 3.3a0 latest from Mercurial, and 2.6.6 that came default on my Ubuntu install). My test involves building a list of one million random integer