Re: Implementaion of random.shuffle

2009-02-20 Thread Scott David Daniels
Steven D'Aprano wrote: On Wed, 18 Jul 2007 19:32:35 +, George Sakkis wrote: ... Wow, can you make a coffee in.. 57ms ? [snip demonstration of xrange raising an exception] Of course! Can't you? And if I use a microwave oven, [*** deleted section outlining Guido's time machine structur

Re: Implementaion of random.shuffle

2007-07-19 Thread Neil Cerutti
On 2007-07-19, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Wed, 18 Jul 2007 19:32:35 +, George Sakkis wrote: > >> On Jul 16, 10:51 pm, Steven D'Aprano >> <[EMAIL PROTECTED]> wrote: >>> On Mon, 16 Jul 2007 16:55:53 +0200, Hrvoje Niksic wrote: >>> > 2**19937 being a really huge number, it's i

Re: Implementaion of random.shuffle

2007-07-18 Thread Steven D'Aprano
On Wed, 18 Jul 2007 19:32:35 +, George Sakkis wrote: > On Jul 16, 10:51 pm, Steven D'Aprano > <[EMAIL PROTECTED]> wrote: >> On Mon, 16 Jul 2007 16:55:53 +0200, Hrvoje Niksic wrote: >> > 2**19937 being a really huge number, it's impossible to exhaust the >> > Mersenne twister by running it in s

Re: Implementaion of random.shuffle

2007-07-18 Thread George Sakkis
On Jul 16, 10:51 pm, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Mon, 16 Jul 2007 16:55:53 +0200, Hrvoje Niksic wrote: > > 2**19937 being a really huge number, it's impossible to exhaust the > > Mersenne twister by running it in sequence. > > "Impossible"? > > Surely this will do it: > > for n

Re: Implementaion of random.shuffle

2007-07-17 Thread Steve Holden
Josiah Carlson wrote: > shabda raaj wrote: [...] > >> Anyway, is there some test harness we can run to test the robustness >> of shuffle? We can run that test harness for large values and see at >> what point all permutations are not possible or come with unequal >> probability. > > Shuffle works

Re: Implementaion of random.shuffle

2007-07-17 Thread Josiah Carlson
shabda raaj wrote: > The code for shuffle is > > if random is None: > random = self.random > for i in reversed(xrange(1, len(x))): > # pick an element in x[:i+1] with which to exchange x[i] > j = int(random() * (i+1)) > x[i], x[

Re: Implementaion of random.shuffle

2007-07-17 Thread Hrvoje Niksic
Steven D'Aprano <[EMAIL PROTECTED]> writes: > In the case of CPython, the current implementation uses the Mersenne > Twister, which has a huge period of 2**19937. However, 2081! is > larger than that number, which means that at best a list of 2081 > items or longer can't be perfectly shuffled (not

Re: Implementaion of random.shuffle

2007-07-17 Thread shabda raaj
Ah, thanks I get it now! --Shabda On Jul 17, 7:52 am, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Mon, 16 Jul 2007 14:45:48 +,shabdaraaj wrote: > > On Jul 16, 5:53 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > >>shabdaraaj wrote: > >> > I was going through the docs for module-random > >>

Re: Implementaion of random.shuffle

2007-07-16 Thread shabda raaj
On Jul 16, 8:29 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > Hrvoje Niksic wrote: > > Steve Holden <[EMAIL PROTECTED]> writes: > > >> So it would appear that the developers chose the Knuth algorithm > >> (with a slight variation) for *their* implementation. Now you have > >> to ask yourself whethe

Re: Implementaion of random.shuffle

2007-07-16 Thread Martin v. Löwis
>> 2**19937 being a really huge number, it's impossible to exhaust the >> Mersenne twister by running it in sequence. > > "Impossible"? Unfeasible. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list

Re: Implementaion of random.shuffle

2007-07-16 Thread Steven D'Aprano
On Mon, 16 Jul 2007 14:45:48 +, shabda raaj wrote: > On Jul 16, 5:53 pm, Steve Holden <[EMAIL PROTECTED]> wrote: >> shabda raaj wrote: >> > I was going through the docs for module-random >> > And I came through >> > this, >> >> > * shuffle*(

Re: Implementaion of random.shuffle

2007-07-16 Thread Steven D'Aprano
On Mon, 16 Jul 2007 16:55:53 +0200, Hrvoje Niksic wrote: > 2**19937 being a really huge number, it's impossible to exhaust the > Mersenne twister by running it in sequence. "Impossible"? Surely this will do it: for n in xrange(2**19937 + 1): random.random() Admittedly, if each call to rand

Re: Implementaion of random.shuffle

2007-07-16 Thread Scott David Daniels
shabda raaj wrote: > ... Oh, I wasn't aware that I could see the source of all python modules Well, actually not _all_ (or is that __all__), but that is exactly why so many of us love Python -- no magic (or at least as little as needed). --Scott David Daniels [EMAIL PROTECTED] -- http://mail

Re: Implementaion of random.shuffle

2007-07-16 Thread Steve Holden
Hrvoje Niksic wrote: > Steve Holden <[EMAIL PROTECTED]> writes: > >> So it would appear that the developers chose the Knuth algorithm >> (with a slight variation) for *their* implementation. Now you have >> to ask yourself whether your surmise is genuinely correct (in which >> case the documentati

Re: Implementaion of random.shuffle

2007-07-16 Thread Hrvoje Niksic
Steve Holden <[EMAIL PROTECTED]> writes: > So it would appear that the developers chose the Knuth algorithm > (with a slight variation) for *their* implementation. Now you have > to ask yourself whether your surmise is genuinely correct (in which > case the documentation may contain a bug) or whet

Re: Implementaion of random.shuffle

2007-07-16 Thread shabda raaj
On Jul 16, 5:53 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > shabda raaj wrote: > > I was going through the docs for module-random > > And I came through this, > > > * shuffle*(x[, random]) > > > Shuffle the sequence x in place. The opti

Re: Implementaion of random.shuffle

2007-07-16 Thread Steve Holden
shabda raaj wrote: > I was going through the docs for module-random > And I came through this, > > * shuffle*( x[, random]) > > > Shuffle the sequence x in place. The optional argument random is a > 0-argument function returning a rand