I have an array of numbers that can range from zero to infinity. I need to generate random numbers lower than that of the numbers in the array, one for each number. For example if i have the numbers:
[10, 5, 0, 7]
An output could be any of:
[5, 3, 0, 6] or [1, 0, 0, 7] or [10, 5, 0, 7]
This is simple enough, but my problem lies with the next part. I have to make sure these numbers add up to a specified value. For example, the same first array could produce:
[4, 3, 0, 1] or [8, 0, 0, 0]
with the total value being 8.
After doing some research, i found this post but sadly, it does not incorporate per-value limits. Rather it has one total, and generates a set of numbers according to that. I need all of these numbers to be less an that of an inputted array. Using Jquery's each
loop, you can create a vale less than that of the number corresponding, but how would i incorporate the total value?
If someone could modify that post to have a three values, being total, max, and min, it would be very appreciated. At this point, i am clueless.