blkerai blkerai - 1 year ago 48
iOS Question

How to generate 4 random number and those 4 number sum must be 100

i want get 4 different random number and their total must be 100 (rN1+rN2+rN3+rn4=100)

Answer Source

Just like this:

NSInteger r1, r2, r3, r4;
r1 = arc4random_uniform(96);
r2 = arc4random_uniform(97-r1);
r3 = arc4random_uniform(98-r1-r2);
r4 = 100-r1-r2-r3;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download