Ask Your Question

Pb with an integer random draw

asked 2020-05-31 22:15:21 +0100

Cyrille gravatar image

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.

candidats= 4 
nn=list([i for i in range(candidats-1)])
PP=([0 for i in nn])
for k in nn:
    PP[k]=RR.random_element(0,elec-sum(PP[j]for j in nn[:k]))

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-06-01 01:23:14 +0100

Cyrille gravatar image

I was persuaded that ZZ was defined by default as RR. In fact I must add ZZ = IntegerRing() and replace RR by ZZ.

edit flag offensive delete link more


ZZ is defined by default:

sage: ZZ
Integer Ring

Maybe you overwrrote it ?

tmonteil gravatar imagetmonteil ( 2020-06-01 01:38:53 +0100 )edit

Certainly since at the begining my code was working. tmonteil thanks to always answer my studip questions.

Cyrille gravatar imageCyrille ( 2020-06-01 15:32:37 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-05-31 22:15:21 +0100

Seen: 183 times

Last updated: Jun 01 '20