random integer with sum constraint
"Karin" wrote:
I want to generate two random integers that fall within a certain range
("min" to "max", e.g. 0 to 10) AND that sum to equal no more than a
given value ("maxsum", e.g. 19)
The first integer is easy (using a Analysis Toolpak add-in)
A1=RANDBETWEEN(min, max)
That presumes min+max <= maxsum. If that assumption is valid in your case,
fine. Otherwise, I think you should write:
A1: =RANDBETWEEN(min, MIN(max, maxsum-min))
Example: if min=1, max=1000 and maxsum=50, random integers from 50 through
1000 are not valid.
But that second integer has me stuck. I started with
A2=RANDBETWEEN(min, maxsum-A1)
That should be:
A2: =RANDBETWEEN(min, MIN(max,maxsum-A1))
----- original message -----
"Karin" wrote in message
...
Hi
I want to generate two random integers that fall within a certain range
("min" to "max", e.g. 0 to 10) AND that sum to equal no more than a given
value ("maxsum", e.g. 19)
The first integer is easy (using a Analysis Toolpak add-in)
A1=RANDBETWEEN(min, max)
But that second integer has me stuck. I started with A2=RANDBETWEEN(min,
maxsum-A1) but then a lot of the results were larger than "max." Oops. Any
ideas on what else I need to put in there?
Thanks,
Karin
|