graded randomness
Ben Bacarisse
ben.usenet at bsb.me.uk
Fri Dec 28 08:17:23 EST 2018
Abdur-Rahmaan Janhangeer <arj.python at gmail.com> writes:
> let us say that i have a box of 5 balls,
>
> green balls - 2 with probability 2/5
> red balls 2 - with probability 2/5
> blue balls 1 - with probability 1/5
>
> how to program the selection so that the random choices reflect the
> probabilities?
>>> import random
>>> random.choice(["green", "green", "red", "red", "blue"])
Not a method that scales particularly well, but there's almost no
context to evaluate solutions.
--
Ben.
More information about the Python-list
mailing list