#!/usr/bin/python
# -*- coding: utf-8 -*-
import random
def number_of_certain_probability(sequence, probability):
x = random.uniform(0, 1)
cumulative_probability = 0.0
for item, item_probability in zip(sequence, probability):
cumulative_probability += item_probability
if x < cumulative_probability:
break
return item
value_list = [0, 1, 2]
probability = [0.5, 0.2, 0.3]
print(number_of_certain_probability(value_list, probability))