Pb with an integer random draw
The following code do nearly what I expect : defining random numbers whose sum equal a given number. Unfortunately, if i change RR
for ZZ
it return an error --- and of course I need integers.
elec=100
candidats= 4
nn=list([i for i in range(candidats-1)])
PP=([0 for i in nn])
PP[0]=RR.random_element(0,elec)
for k in nn:
PP[k]=RR.random_element(0,elec-sum(PP[j]for j in nn[:k]))
show(PP)
show(sum(PP))
I do not understand my error since it was working at the beginning. Also the sum was nearly always equal to elec with some time a unit of difference. Also is there a command to shuffle the number inside the list.