Does anybody know if there is any equivalent to
import random
random.choices(population, weitghts, k=1)
.. for Python Mode for Processing?.
I want to deploy an algorithm for this StackOverflow question, but can't find the desired function.
Does anybody know if there is any equivalent to
import random
random.choices(population, weitghts, k=1)
.. for Python Mode for Processing?.
I want to deploy an algorithm for this StackOverflow question, but can't find the desired function.
Python mode for Processing is built on Jython, and Jython still hasn't crawled out of the Python 2 era (it only moved to Python 2.7 compatibility, from 2.5, in 2015, half a decade after 2.7 released).
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, so you could always just backport it to Python 2 yourself (along with itertools.accumulate
, which it relies on).