随机洗牌 [英] random shuffles

查看:69
本文介绍了随机洗牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




x.sort(cmp = lambda x,y:cmp(random.random(),0.5))


选择随机抽取的x均匀分布?


直观地说,假设list.sort()对

进行最小数量的比较实现排序,我我说答案是肯定的。但我感觉不太舒服

凭直觉......谁能想到更坚实的论证呢?


- BB

-

" On na ?? t tous les m?¨tresdum?ame monde"

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 ?

- BB
--
"On na??t tous les m?¨tres du m?ame monde"

推荐答案

Boris Borcic写道:
Boris Borcic wrote:

确实


x.sort(cmp = lambda x,y:cmp( random.random(),0.5))


随机抽取x均匀分布?


直观地,假设list.sort( )对b / b
进行最小数量的比较,我会说答案是肯定的。但是,我觉得自己并不觉得这种直觉很舒服......有人能想到一个更坚实的讨论吗?
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 ?



轶事证据表明答案是否定的:

Anecdotal evidence suggests the answer is no:


>> histo = {}
我在xrange(1000):
>>histo = {}
for i in xrange(1000):



.... t =元组(排序(范围(3),lambda x,y:cmp(random.random(),0.5)))

.... histo [t] = histo .get(t,0)+ 1

....

.... t = tuple(sorted(range(3), lambda x, y: cmp(random.random(), 0.5)))
.... histo[t] = histo.get(t, 0) + 1
....


>>已排序(histo.values())
>>sorted(histo.values())



[60,62,64,122,334, 358]


对:

[60, 62, 64, 122, 334, 358]

versus:


> > histo = {}
for x in xrange(1000):
>>histo = {}
for i in xrange(1000):



.... t = tuple( sorted(range(3),key = lambda x:random.random()))

... .histo [t] = histo.get(t,0)+ 1

....

.... t = tuple(sorted(range(3), key=lambda x: random.random()))
.... histo[t] = histo.get(t, 0) + 1
....


>> sorted(histo.values())
>>sorted(histo.values())



[147,158] ,160,164,183,188]


彼得

[147, 158, 160, 164, 183, 188]

Peter




Boris Borcic写道:

Boris Borcic wrote:

确实


x.sort(cmp = lambda x,y:cmp(random.random(),0.5))


随机抽取x均匀分布?


直观地说,假设list.sort()与
达到排序,我会说答案是肯定的。但我感觉不太舒服

凭直觉......谁能想到更坚实的论证?
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 ?



为什么不使用提供的shuffle方法?


random.shuffle(x)

Why not use the supplied shuffle method?

random.shuffle(x)




Dustan写道:

Dustan wrote:

Boris Borcic写道:
Boris Borcic wrote:

确实


x.sort(cmp = lambda x,y:cmp(random.random(),0.5))

随机选择x随机均匀分布?


直观地说,假设list.sort()与

进行最小数量的比较实现这种,我会说答案是肯定的。但我感觉不太舒服

凭直觉......谁能想到更坚实的论证?
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 ?



为什么不使用提供的shuffle方法?


random.shuffle(x)


Why not use the supplied shuffle method?

random.shuffle(x)



或查看此主题:
http://groups.google.com/group/comp....vc=2&a​​mp;q=shuffle


Iain

or check out this thread:
http://groups.google.com/group/comp....vc=2&q=shuffle

Iain


这篇关于随机洗牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆