Python处理中是否有任何random.choices()函数

时间:2018-11-09 02:44:12

标签: python processing

有人知道是否有等同于

import random
random.choices(population, weitghts, k=1)

.. for Python Mode for Processing?。

我想为this StackOverflow问题部署算法,但找不到所需的函数。

1 个答案:

答案 0 :(得分:1)

用于处理is built on Jython, and Jython still hasn't crawled out of the Python 2 era的Python模式(在2.7发布后的五年之内,它从2015年的2.5升级到Python 2.7兼容性)。

random.choices was introduced in Python 3.6;即使用于处理的Python模式提供了对所有Python功能的完全访问权限(并且我很难确定是否可以使用),但Jython 2.7的兼容性意味着它在Python 3.1之后几乎没有引入任何功能,因此random.choices在没有从头开始重新实现它。当然,random.choices is open source and posted online的代码也是如此,因此您总是可以自己将其反向移植到Python 2(以及它所依赖的itertools.accumulate)。