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

Is there any random.choices() function in Python Processing

有谁知道是否有任何等同于

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

.. 对于 Python Mode for Processing?.

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

Python 处理模式 is built on Jython, and Jython still hasn't crawled out of the Python 2 era(它仅在 2015 年从 2.5 移至 Python 2.7 兼容性,即 2.7 发布后的五年)。

random.choices was introduced in Python 3.6; even if Python mode for Processing offered full access to all Python features (and I have a hard time determining if it does), Jython's 2.7 compatibility means it has almost no features introduced after Python 3.1, so random.choices is not available without reimplementing it from scratch. Of course, the code for random.choices is open source and posted online,因此您始终可以自己将其反向移植到 Python 2(以及它所依赖的 itertools.accumulate)。