import random

# CDI not working yet due to python version problems

# Pre: |W| = |X| > 1
def select(X,W):
	rand = random.random()
	S = sum(W)
	acc = 0
	for i in range(len(W)):
		acc += W[i]/float(S)
		if rand < acc:
			return X[i]
	return "Error: the format of one of the lists is incorrect"

# Test
L = [0]*3
for i in range(10000):
	s = select(range(4),[3,2,5])
	L[s] += 1
print(L)