from random import random
from math import sqrt

val =  [  1 ,  2 ,   5,  -3 ]
proba =  [ 0.1, 0.5, 0.3, 0.1 ]

def simul_tirage(val, proba):
	t = random()
	s = proba[0]
	k = 0
	while t > s:
		k = k + 1
		s = s + proba[k]
	return val[k]

def simul_ech(val, proba, n):
	res = [0,0,0,0]
	for J in range (n):
		tirage = simul_tirage(val, proba)
		for k in range(4):
			if val[k] == tirage:
				res[k] = res[k] + 1 
	for k in range(4):
		res[k] = ...
	return res

def esp_var(val, proba):
	s = 0
	for k in range(4):
		s = s + val[k]*proba[k]
	return s

def var_var(val, proba):
	s = 0
	e = esp_var(val, proba)
	for k in range(4):
		...
	return s

def proportions(val, proba, n, N):
	res = [0,0,0]
	mu = esp_var(val, proba)
	sigma = sqrt(var_var(val, proba))
	for j in range (N):
		ech = simul_ech(val, proba, n)
		moy = esp_var( val, ech)
		if abs(moy - mu) < sigma/sqrt(n):
			res[0] = res[0] + 1
		if ... :
			res[1] = res[1] + 1
		if ... :
			res[2] = res[2] + 1
	for k in range(3):
		res[k] = res[k]/N
	return res

# simulation
print(proportions(val, proba, 100, 1000))
