PDA

View Full Version : Help with random numbers


,TomY'
17/07/2018, 10:24 AM
Hi all. I would like to create system: it will be 5 variables, after my action system will add random number to all variables, but total amount will be 100 ( variable1 + variable2 + variable3 + variable4 + variable5 = 100 ). How to create it? I know, how to create variables, add random number, but how to keep total amount = 100?

CodeStyle175
17/07/2018, 10:34 AM
new var[5];
for(new i; i < 4; i++)var[i]=10+random(10);
var[4]=100-var[3]-var[2]-var[1]-var[0];

,TomY'
17/07/2018, 11:53 AM
Thanks man!!! ;)