Possible Duplicate:
How to make 5 random numbers with sum of 100
i am new with php . Can i ask how to make 3 random number with range an sum of 3 numbers = max value of this range.
Example : i have range 0->900; 3 random number is 213 437 250
Possible Duplicate:
How to make 5 random numbers with sum of 100
i am new with php . Can i ask how to make 3 random number with range an sum of 3 numbers = max value of this range.
Example : i have range 0->900; 3 random number is 213 437 250
Pick two random numbers between 0 and 900 inclusive. Add 0 and 900 to the list. Sort them. Your numbers are the 3 differences between successive numbers.
For example, say you pick 503 and 117. Your sorted list is 0, 117, 503, 900. So your differences are:
117 - 0 = 117
503 - 117 = 386
900 - 503 = 397
So your three numbers are 117, 386, and 397.
Since you only need three numbers, you can simplify the process: Generate two random numbers between 0 and 900 (inclusive). Call the larger A and the smaller B. Your numbers are B
, A - B
and 900 - A
.