模拟与python列表一起使用的卡片洗牌技术

shuffle的Python项目详细描述


一个简单的python模块,用来模拟对python列表进行洗牌的动作,就好像它是一副牌一样。

类型

膛线

http://en.wikipedia.org/wiki/Shuffling#Riffle

可预测的行为,使人的来福枪洗牌不完美

一旦一副牌被分到每只手上,每只手上的牌的数量就不可能相等。 当每个拇指从半张牌中释放出来时,有时一次会有多张牌从一只手上掉下来。 当每只手的牌堆越来越薄时,每只手的牌堆掉落的概率就会增加。

shuffle.riffle(List original[, int shuffles])

外伸

http://en.wikipedia.org/wiki/Shuffling#Stripping_or_overhand

可预测的行为,使人上手洗牌不完美

随机数量的卡(块)从顶部取出,按相反顺序放在另一只手上(保持每个块内的顺序):

shuffle.overhand(List original[, int shuffles])

蒙哥人

http://en.wikipedia.org/wiki/Shuffling#Mongean_shuffle

一种非常可预测的洗牌,交替地将最上面的牌放在新牌组的底部/顶部。

shuffle.mongean(List original[, int shuffles])

http://en.wikipedia.org/wiki/Shuffling#Pile_shuffle

可预测的洗牌,将项目处理成n堆,然后重新组合这些堆。

shuffle.pile(List original, int piles[, int shuffles])

安装

pip install shuffle

git clone git://github.com/jondavidjohn/Card-Shuffle-for-Python.git shuffle
cd ./shuffle
sudo python setup.py install

linux用户-确保安装了python dev包。

用法

import shuffle
riffled_list = shuffle.riffle(original_list, 3)  # riffles the list 3 times
overhanded_list = shuffle.overhand(original_list, 2)  #overhand's the list 2 times
mongeaned_list = shuffle.mongean(original_list, 5)  #mongean shuffle 5 times
piled_list = shuffle.pile(original_list, 3, 6)  #pile shuffle, using 3 piles, 6 times

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
junit cucumber为什么会找到“runTest.java”来运行测试?   在Eclipse中找不到java KeyPairGenerator   java NotSerializableException即使在实现Serializable之后   noclassdeffounderror(java字符串连接)为什么会出现这种异常?   java Guice:将接口绑定到由动态代理创建的实例   使用Spring数据neo4j创建空间索引时发生java错误   java对于需要在50多个excel文件上运行并且每个文件平均包含25k行的项目,最佳的方法是什么   javaNIO中的java缓冲区写入/发送消息问题   如何在Java/eclipse中添加不调用super()的警告   JavaSpring:mvcUrl映射错误的id   java应该在getInstance或构造函数中使用Init方法吗?   安卓中的java空指针异常错误   java Jsoup不能完全获取原始html代码