Probabilities = {'A': 0.25, 'C': 0.25, 'G': 0.25, 'T': 0.25} def WeightedDie(Probabilities): import random r = random.uniform(0, 1) letter = '' for symbol in "ACGT": if r >= 0 and r <= Probabilities['A']: letter = 'A' elif r >= Probabilities['A'] and r <= (Probabilities['A'] + Probabilities['C']): letter = 'C' elif r >= (Probabilities['A'] + Probabilities['C']) and r <= (Probabilities['A'] + Probabilities['C'] + Probabilities['G']): letter = 'G' elif r >= (Probabilities['A'] + Probabilities['C'] + Probabilities['G']) and r <= (Probabilities['A'] + Probabilities['C'] + Probabilities['G'] + Probabilities['T']): letter = 'T' return letter I need a function for randomly selecting events with given probabilities. When I set the intervals, I get the data on the key. However, the keys can be called differently, not necessarily ACGT, and then my function will not work. That's the problem.