random shuffles

Iain King iainking at gmail.com
Fri Jul 21 08:34:36 EDT 2006


Dustan wrote:
> Boris Borcic wrote:
> > does
> >
> > x.sort(cmp = lambda x,y : cmp(random.random(),0.5))
> >
> > pick a random shuffle of x with uniform distribution ?
> >
> > Intuitively, assuming list.sort() does a minimal number of comparisons to
> > achieve the sort, I'd say the answer is yes. But I don't feel quite confortable
> > with the intuition... can anyone think of a more solid argumentation ?
>
> Why not use the supplied shuffle method?
>
> random.shuffle(x)

or check out this thread:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/766f4dcc92ff6545?tvc=2&q=shuffle

Iain




More information about the Python-list mailing list