I need to generate 7 random numbers between -1,1 which sum of them equals to 1. I used this code to do so.
diff(c(0, sort(round(runif(7,-1,1),2)), 0))
But I have a big problem with this.
one output of this code is -0.89 0.21 0.00 0.21 0.30 0.19 0.61 -0.63 the problem is it is uniform I guess so it every time generates big random numbers in the first and last number which is not I want. I need it to be spread to all numbers. ex. 0.22 -.21 .33 -.12 0.11 0.35 -0.08 (the sum is not equal to 1 just an example) Do you know who I can write a code to get this kind of random numbers?
thanks
Aucun commentaire:
Enregistrer un commentaire