After Effects expressions to sum numbers and control charts_2
If you use random(50) for the first three numbers the average value of their sum will be 75. So you can simply make the last number 100 - (num1 + num2 + num3).
However there is a chance that the three numbers could add to more than 100—up to 150 in the edge case that random(50) gives the result 50 for each one, thus summing to 150. So you could make the third number random(Math.min(50, 100 - (num1 + num2))). This would mean that if the first two numbers added together were more than 50 it would limit the maximum value of the third number to equal or be less than enough to make the sum total 100. I'm not a statistician so I don't know if this would mathematically be perfectly random, but that usually doesn't matter for the purposes of motion graphics.
Which begs the question: why not just make all four numbers just random(50)? Over time the sum will tend towards exactly 100, it might just not add up to 100 at any one time.
But whatevs, the expression for scale would be:
Scale (bar1 )
r = random(100);
[ r, 100 ]

Scale (bar2 )
r = random(100 - thisComp.layer(&quot;bar1&quot;).transform.scale[0]);
[ r, 100 ]

Scale (bar3)
oneTwoTotal = thisComp.layer(&quot;bar1&quot;).transform.scale[0] + thisComp.layer(&quot;bar2&quot;).transform.scale[0];
r = random(Math.min(50, 100 - oneTwoTotal));
[r, 100]

Scale (bar4)
r = 100 - (thisComp.layer(&quot;bar1&quot;).transform.scale[0] + thisComp.layer(&quot;bar2&quot;).transform.scale[0]  + thisComp.layer(&quot;bar3&quot;).transform.scale[0] );
[r, 100]