I have developed a probabilistic function of variant choice. I copy a reproducible example below. The function takes a list of n variants and a list of n probabilities. Then it creates a list of floating-point numbers, which determine n ordered numeric breakpoints, one for each variant. Then it generates a random number and the corresponding choice according to the set of ordered numeric breakpoints.
from __future__ import division
from random import random
from bisect import bisect
def choice(variant, probs):
prob_cumulative = list()
aux = 0
for p in probs:
aux += p
prob_cumulative.append(aux)
r = random() * prob_cumulative[-1]
op = bisect(prob_cumulative, r)
print(aux)
print(prob_cumulative)
print(r)
print(op)
return variants[op]
variants=["S","M","N","G"]
probs=[0.8,0,0.1,0.1]
print(choice(variants, probs))
I would like to be able to describe this function using formal maths. I appreciate any answer or suggestion.