# all portions are stored in a list 
all_portions = [7,5,4,2,6,1];

# let's calculate the total portion
total_portion = 0
for i in range(6):
    total_portion = total_portion + all_portions[i]

print("total portion is",total_portion)

# find the weight of one portion
one_portion = 1/total_portion
print("the weight of one portion is",one_portion)

print() # print an empty line
# now we can calculate the probabilities of rolling 1,2,3,4,5, and 6
for i in range(6):
    print("the probability of rolling",(i+1),"is",(one_portion*all_portions[i]))

# we will randomly create a probabilistic state
#
# we should be careful about two things:
#     1. a probability value must be between 0 and 1
#     2. the total probability must be 1
#
# therefore, we can randomly pick three probability values.
# once we have three probability values, the fourth one is determined automatically
# the fourth one cannot be arbitrary, because the summation of the four values must be 1

# let's use a list of size 4
# initial values are zeros
my_state = [0,0,0,0]

# we pick three random probabilistic values
from random import randrange

# I assume that I have the following total value to distribute to four parts
total = 1000
# I will randomly pick a value, and then continue with the remaining value
for i in range(3): # let's find the three values
    pick_a_value = randrange(total)
    print("I picked",pick_a_value)
    my_state[i] = pick_a_value
    total = total - pick_a_value # remaining value for the others
my_state[3] = total # this is the remaining value after three iterations
print("The remaining value is",total)

# let's verify the summation of the elements in my_state
sum = 0
print() # print an empty line
for i in range(len(my_state)):
    sum = sum + my_state[i]
print("the summation of the elements in my_state is",sum)

# let's convert the selected values to the probabilities
# we can also call this procedure as **NORMALIZATION**
for i in range(len(my_state)):
    my_state[i] = my_state[i]/1000

print() # print an empty line
print("the entries of my probabilistic state:")
# let's print all probabilities
for i in range(len(my_state)): print(my_state[i])