<s> import bisect <EOL> from faker . generator import random <EOL> def random_sample ( ) : <EOL> return random . uniform ( <NUM_LIT:0.0> , <NUM_LIT:1.0> ) <EOL> def cumsum ( it ) : <EOL> total = <NUM_LIT:0> <EOL> for x in it : <EOL> total += x <EOL> yield total <EOL> def choice_distribution ( a , p ) : <EOL> assert len ( a ) == len ( p ) <EOL> cdf = list ( cumsum ( p ) ) <EOL> normal = cdf [ - <NUM_LIT:1> ] <EOL> cdf2 = [ float ( i ) / float ( normal ) for i in cdf ] <EOL> uniform_sample = random_sample ( ) <EOL> idx = bisect . bisect_right ( cdf2 , uniform_sample ) <EOL> return a [ idx ] </s>
