generating a set of random numbers to total a set value

yaldan

New Member
Joined
Jan 15, 2007
Messages
1
Is it possible to generate a set of random numbers between say 50 - 150 whereby the sum of those random numbers totals a value in the spreadsheet which is determined by two other values in the spreadsheet?

Eg: value 1 = 10, value 2 = 300. The difference = 290. Now generate 6 or so random numbers between 50 - 150 that come to a total of 290.

If so could you helpme with formula or script.

Regards

Yaldan
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
If you had 6 random numbers between 50 and 150, even if they were all 50, they would never sum to 290.
 
Upvote 0
Enter the formula =randbetween(50,150) in cells G11:G16, and =sum(g11:g16) in cell G18.

This will generate 6 random numbers between 50 and 150, and their sum.

If you target value is in D18, then the following will refresh the random values until the values in D18 and G18 are equal.

Do Until Range("g18").Value = Range("d18").Value
Calculate
Loop


End


However, you would need some form of error trapping to make sure that your target value is never less than (6 * 50) 300, and never more than (6 * 150) 900, otherwise you would go into and endless loop as you cant reconcile between the two numbers
 
Upvote 0
Generate six Random numbers in Range A1:A6 [=rand()]

Cell A9 enter your target sum total

In Cell A8 a formula to devide the target sum by the sum of the six random numbers:
=(A9/(SUM(A1:A6)))

Range B1:B6 multiply each of the six random numbers by contents of Cell A8
=A1*$A$8

Cell B8 Run a check:
=SUM(B1:B7)
 
Upvote 0
Generate six Random numbers in Range A1:A6 [=rand()]

Cell A9 enter your target sum total

In Cell A8 a formula to devide the target sum by the sum of the six random numbers:
=(A9/(SUM(A1:A6)))

Range B1:B6 multiply each of the six random numbers by contents of Cell A8
=A1*$A$8

Cell B8 Run a check:
=SUM(B1:B7)

You are genius....
I have been looking for this and everybody said it is impossible.....
 
Upvote 0
Generate six Random numbers in Range A1:A6 [=rand()]

Cell A9 enter your target sum total

In Cell A8 a formula to devide the target sum by the sum of the six random numbers:
=(A9/(SUM(A1:A6)))

Range B1:B6 multiply each of the six random numbers by contents of Cell A8
=A1*$A$8

Cell B8 Run a check:
=SUM(B1:B7)

What do we do if we need those numbers to be an integer ? Please help...
 
Upvote 0
You could do something like this:

Excel 2010
ABCD
1TargetMinMaxNumber of random numbers
21005257
3
47
519
618
719
818
910
109

<colgroup><col style="width: 25pxpx"><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
A4=RANDBETWEEN(B2,C2)
A5=IF(ROW()=$D$2+3,$A$2-SUM(OFFSET($A$4,0,0,$D$2-1)),IF(ROW()>$D$2+3,"",RANDBETWEEN($B$2,$C$2)))
B4=IF(OR($C$2*D$2<$A$2,$B$2*$D$2>$A$2),"Can't be done!","")

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>



Put the values in A2:D2 that you want. Put the formula in A4. Then put the formula in A5 and copy down as far as you need. The last number in the list (A10 in this example) is a calculated number designed to make the list add up. It could theoretically be less than the minimum or higher than the maximum. If that happens, just press F9 to recalculate until you get a valid number. The formula in B4 is just a check to see if the values in A2:D2 are viable.

Let me know if this helps.
 
Upvote 0
You could do something like this:

Excel 2010
ABCD
1TargetMinMaxNumber of random numbers
21005257
3
47
519
618
719
818
910
109

<tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
A4=RANDBETWEEN(B2,C2)
A5=IF(ROW()=$D$2+3,$A$2-SUM(OFFSET($A$4,0,0,$D$2-1)),IF(ROW()>$D$2+3,"",RANDBETWEEN($B$2,$C$2)))
B4=IF(OR($C$2*D$2<$A$2,$B$2*$D$2>$A$2),"Can't be done!","")

<tbody>
</tbody>

<tbody>
</tbody>



Put the values in A2:D2 that you want. Put the formula in A4. Then put the formula in A5 and copy down as far as you need. The last number in the list (A10 in this example) is a calculated number designed to make the list add up. It could theoretically be less than the minimum or higher than the maximum. If that happens, just press F9 to recalculate until you get a valid number. The formula in B4 is just a check to see if the values in A2:D2 are viable.

Let me know if this helps.

Thanks for your answer

What I need in my particular situation is 2 numbers both of which does not exceed 25 but also not less than 10 to target 50 when added to each other. But in this example the generated numbers can exceed my maximum.
I would be really glad if you could help.
Thanks again

Screen_Shot_2016_02_09_at_20_32_26.png
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,550
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top