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
 
I'm glad I could help. I'm one of the few people left in the world who's not on Facebook. If you have a question, send me a message here and I'll get back to you.

Respected Sir Mr. Eric,
Nice to hear from you.... thanksss again..... sure i'll contact you.. nice to meet you.
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
OK, I created some formulas that will always generate a valid set of numbers, with no repeated F9. But as I warned you, the formulas are more complicated.

Excel 2010
ABCD
TargetMinMaxNumber of random numbers

<tbody>
[TD="align: center"]1[/TD]

[TD="align: center"]2[/TD]
[TD="align: right"]100[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]25[/TD]
[TD="align: right"]7[/TD]

[TD="align: center"]3[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]4[/TD]
[TD="align: right"]20[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]5[/TD]
[TD="align: right"]21[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]6[/TD]
[TD="align: right"]22[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]7[/TD]
[TD="align: right"]18[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]8[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]9[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]10[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]100[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
Sheet1

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<tbody>[TR="bgcolor: #DAE7F5"]
[TH]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
[TR]
[TH="bgcolor: #DAE7F5"]A4[/TH]
[TD="align: left"]=RANDBETWEEN(MAX($B$2,$A$2-(($D$2-ROWS($A$4:$A4))*$C$2)),MIN($C$2,$A$2-(($D$2-ROWS($A$4:$A4))*$B$2)))[/TD]
[/TR]
[TR]
[TH="bgcolor: #DAE7F5"]A5[/TH]
[TD="align: left"]=IF(ROW()=$D$2+3,$A$2-SUM($A$4:$A4),IF(ROW()>$D$2+3,"",RANDBETWEEN(MAX($B$2,$A$2-(SUM($A$4:$A4)+($D$2-ROWS($A$4:$A5))*$C$2)),MIN($C$2,$A$2-(SUM($A$4:$A4)+($D$2-ROWS($A$4:$A5))*$B$2)))))[/TD]
[/TR]
[TR]
[TH="bgcolor: #DAE7F5"]B4[/TH]
[TD="align: left"]=IF(OR($C$2*D$2<$A$2,$B$2*$D$2>$A$2),"Can't be done!","")[/TD]
[/TR]
[TR]
[TH="bgcolor: #DAE7F5"]B10[/TH]
[TD="align: left"]=SUM(A4:A20)[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]



Here's your 2-number example:
Excel 2010
ABCD
TargetMinMaxNumber of random numbers

<tbody>
[TD="align: center"]1[/TD]

[TD="align: center"]2[/TD]
[TD="align: right"]50[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]25[/TD]
[TD="align: right"]2[/TD]

[TD="align: center"]3[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]4[/TD]
[TD="align: right"]25[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]5[/TD]
[TD="align: right"]25[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]6[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]7[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]8[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]9[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]10[/TD]

[TD="align: right"]50[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
Sheet1



From your example in post #13:
Excel 2010
ABCD
TargetMinMaxNumber of random numbers

<tbody>
[TD="align: center"]1[/TD]

[TD="align: center"]2[/TD]
[TD="align: right"]35[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]25[/TD]
[TD="align: right"]2[/TD]

[TD="align: center"]3[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]4[/TD]
[TD="align: right"]18[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]5[/TD]
[TD="align: right"]17[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]6[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]7[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]8[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]9[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]10[/TD]

[TD="align: right"]35[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
Sheet1



Since your numbers 3 and 4 are fixed, subtract their total (50) from the overall total (85) to get the value (35) that numbers 1 and 2 must sum to.


Greeting sir,

i've got task from my sister to help her make formula, would you like to help me create random number for specific criteria, any help would be appreciated

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[TD]H[/TD]
[TD]I[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]List Of Fixed Number as Criteria[/TD]
[TD]Number of random numbers[/TD]
[TD][/TD]
[TD]Mark1[/TD]
[TD]Mark2[/TD]
[TD]Mark3[/TD]
[TD]Mark4[/TD]
[TD]Mark5[/TD]
[TD]SUM of fix number[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]0[/TD]
[TD]5[/TD]
[TD][/TD]
[TD]0[/TD]
[TD]15[/TD]
[TD]20[/TD]
[TD]20[/TD]
[TD]20[/TD]
[TD]75[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]5[/TD]
[TD][/TD]
[TD][/TD]
[TD]15[/TD]
[TD]20[/TD]
[TD]5[/TD]
[TD]10[/TD]
[TD]5[/TD]
[TD]55[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]10[/TD]
[TD][/TD]
[TD][/TD]
[TD]20[/TD]
[TD]20[/TD]
[TD]20[/TD]
[TD]20[/TD]
[TD]20[/TD]
[TD]100[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]15[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6
[/TD]
[TD]20[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


i would like to make mark1-5 to be random from specific number in column A to sum specific number in column I

pls help me figured out the exact formula.

thx in advanced
 
Upvote 0
You could do something like this:

Excel 2010
ABCD
TargetMinMaxNumber of random numbers

<tbody>
[TD="align: center"]1[/TD]

[TD="align: center"]2[/TD]
[TD="align: right"]100[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]25[/TD]
[TD="align: right"]7[/TD]

[TD="align: center"]3[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]4[/TD]
[TD="align: right"]7[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]5[/TD]
[TD="align: right"]19[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]6[/TD]
[TD="align: right"]18[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]7[/TD]
[TD="align: right"]19[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]8[/TD]
[TD="align: right"]18[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]9[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]10[/TD]
[TD="align: right"]9[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
Sheet1

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<tbody>[TR="bgcolor: #DAE7F5"]
[TH]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
[TR]
[TH="bgcolor: #DAE7F5"]A4[/TH]
[TD="align: left"]=RANDBETWEEN(B2,C2)[/TD]
[/TR]
[TR]
[TH="bgcolor: #DAE7F5"]A5[/TH]
[TD="align: left"]=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)))[/TD]
[/TR]
[TR]
[TH="bgcolor: #DAE7F5"]B4[/TH]
[TD="align: left"]=IF(OR($C$2*D$2<$A$2,$B$2*$D$2>$A$2),"Can't be done!","")[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]



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.


Hi Eric,

I have been looking for something like that for ages. Thank you so much for sharing your knowledge.

Is there a way to avoid negative number?



[TABLE="width: 344"]
<colgroup><col style="width:48pt" width="64"> <col style="width:74pt" width="98"> <col style="width:48pt" width="64"> <col style="width:89pt" width="118"> </colgroup><tbody>[TR]
[TD="width: 64"]Target[/TD]
[TD="width: 98"]Min[/TD]
[TD="width: 64"]Max[/TD]
[TD="width: 118"]Number of radom[/TD]
[/TR]
[TR]
[TD="align: right"]5[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]5[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]0[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]-2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
I'm glad you found it useful.

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.

That's why you're getting a negative number in the last row. Just press F9 to get a different set of answers. If you want the formulas to make sure that the numbers are valid without F9, refer to the set of formulas in post #14. More complicated, but you won't get any negative numbers.


Hope this helps!
 
Upvote 0
I'm glad you found it useful.


That's why you're getting a negative number in the last row. Just press F9 to get a different set of answers. If you want the formulas to make sure that the numbers are valid without F9, refer to the set of formulas in post #14. More complicated, but you won't get any negative numbers.


Hope this helps!


Thanks Eric. Fantastic formula. You saved me a big headache. Thank you so much for sharing your knowledge with your the world :-)
 
Upvote 0
Hey Eric I'm wondering if you could help me with a complication to this. I'd like to have a list of items in a sheet and step by step want the following to happen:

For a set item I want it to generate a set number between 3-5. Along with a secondary number between 8-15

Next I want to generate 4-5 more items from the listed.

Then generate a set number 4-5 for each along with a corresponding number between 10-20.

I want all items to add to 280+

You could use exercise as an example:
Set item is: Bench Press: random set number is 4. Random corresponding (rep) number is 12. Total is 48

Now have 4- 5 more items chosen from a list of supplementary movements.

If it was 4 then the totals would have to equal or surpass 232.

Let me know if that makes sense and thank you for any help ahead of time.
 
Upvote 0
Welcome to the forum!

Sorry I didn't reply sooner. I usually unsubscribe from threads when they seem to be resolved, and I just happened to notice this. In any event, here's my first stab at it:

ABCDEFG
ExercisesListSetsRepsTotalRunning Total
Bench PressPull ups
SquatsSquats
Push-upsCurls
CurlsBurpees
Sit-upsChin ups
Leg RaisesLeg Raises
Chin upsBench Press
Pull ups
Crunches
Burpees

<tbody>
[TD="align: center"]1[/TD]

[TD="align: right"][/TD]

[TD="align: center"]2[/TD]

[TD="align: right"][/TD]

[TD="align: right"]3[/TD]
[TD="align: right"]15[/TD]
[TD="align: right"]45[/TD]
[TD="align: right"]45[/TD]

[TD="align: center"]3[/TD]

[TD="align: right"][/TD]

[TD="align: right"]3[/TD]
[TD="align: right"]9[/TD]
[TD="align: right"]27[/TD]
[TD="align: right"]72[/TD]

[TD="align: center"]4[/TD]

[TD="align: right"][/TD]

[TD="align: right"]3[/TD]
[TD="align: right"]15[/TD]
[TD="align: right"]45[/TD]
[TD="align: right"]117[/TD]

[TD="align: center"]5[/TD]

[TD="align: right"][/TD]

[TD="align: right"]3[/TD]
[TD="align: right"]15[/TD]
[TD="align: right"]45[/TD]
[TD="align: right"]162[/TD]

[TD="align: center"]6[/TD]

[TD="align: right"][/TD]

[TD="align: right"]5[/TD]
[TD="align: right"]15[/TD]
[TD="align: right"]75[/TD]
[TD="align: right"]237[/TD]

[TD="align: center"]7[/TD]

[TD="align: right"][/TD]

[TD="align: right"]3[/TD]
[TD="align: right"]13[/TD]
[TD="align: right"]39[/TD]
[TD="align: right"]276[/TD]

[TD="align: center"]8[/TD]

[TD="align: right"][/TD]

[TD="align: right"]3[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]30[/TD]
[TD="align: right"]306[/TD]

[TD="align: center"]9[/TD]

[TD="align: right"][/TD]

[TD="align: center"]10[/TD]

[TD="align: right"][/TD]

[TD="align: center"]11[/TD]

[TD="align: right"][/TD]

[TD="align: center"]12[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]13[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]14[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]15[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]16[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]17[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]18[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]19[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]20[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
Sheet1

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<tbody>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TH]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
[TR]
[TH="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]D2[/TH]
[TD="align: left"]=IF(C2="","",RANDBETWEEN(3,5))[/TD]
[/TR]
[TR]
[TH="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]E2[/TH]
[TD="align: left"]=IF(C2="","",RANDBETWEEN(8,15))[/TD]
[/TR]
[TR]
[TH="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]F2[/TH]
[TD="align: left"]=IF(C2="","",D2*E2)[/TD]
[/TR]
[TR]
[TH="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]G2[/TH]
[TD="align: left"]=IF(C2="","",SUM($F$2:F2))[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Array Formulas[TABLE="width: 100%"]
<tbody>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TH]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
[TR]
[TH="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]C2[/TH]
[TD="align: left"]{=IF(SUM($F$1:$F1)>280,"",INDEX(A:A,SMALL(IF(ISERROR(MATCH($A$2:$A$20,$C$1:$C1,0)),ROW($A$2:$A$20)),RANDBETWEEN(1,COUNTA(A:A)-ROW()+1)))&"")}[/TD]
[/TR]
</tbody>[/TABLE]
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself[/TD]
[/TR]
</tbody>[/TABLE]



You have a list of exercises in column A. The formulas allow you to enter whatever you want up to row 20, but we can raise that if needed. Then the formula in C2 randomly selects an exercise from column A. As you drag down, it ensures you don't get duplicates. Then D2 generates a random number 3-5, E2 generates a random number 8-15, F2 is D2*E2, and G2 is a running total of column F. When that total exceeds 280, the formula in C will not generate any more exercises. Press F9 to get a different set.

In this example, the running total hit 276 on the Leg Raises. I considered tweaking the formulas to round up the last exercise, either the sets or reps, so that I don't need to list another exercise. But that's probably much easier to do by just looking at it.

In any case, take a look at it and let me know what you think.
 
Upvote 0
hi Eric,

do you maybe have a formula that would total to specific value in both rows and columns?
the thing is that I need random data table that has specific sums across row and columns.

thanks,
Veljko

Here is a version that works horizontally, with 5 values as in your example:

Excel 2010
ABCDEFGHIJKLM
Mark1Mark2Mark3Mark4Mark5Total

<tbody>
[TD="align: center"]1[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] "]Min[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] "]Max[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] "]Number of random numbers[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]2[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"]5[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"]25[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"]5[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]3[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]11[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]34[/TD]
[TD="align: right"][/TD]

[TD="align: center"]4[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]17[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]39[/TD]
[TD="align: right"][/TD]

[TD="align: center"]5[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]13[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"]9[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"]43[/TD]
[TD="align: right"][/TD]

[TD="align: center"]6[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"] #NUM ![/TD]
[TD="align: right"] #NUM ![/TD]
[TD="align: right"] #NUM ![/TD]
[TD="align: right"] #NUM ![/TD]
[TD="align: right"] #NUM ![/TD]
[TD="align: right"]23[/TD]
[TD="align: right"][/TD]

[TD="align: center"]7[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]8[/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FAFAFA]#FAFAFA[/URL] , align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
Sheet15

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<tbody>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TH]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
[TR]
[TH="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]G3[/TH]
[TD="align: left"]=RANDBETWEEN(MAX($B$2,L3-(($D$2-COLUMNS($G3:G3))*$C$2)),MIN($C$2,L3-(($D$2-COLUMNS($G3:G3))*$B$2)))[/TD]
[/TR]
[TR]
[TH="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]H3[/TH]
[TD="align: left"]=IF(COLUMN()=$D$2+COLUMN($G$3)-1,$L3-SUM($G3:G3),IF(COLUMN()>$D$2+COLUMN($G$3)-1,"",RANDBETWEEN(MAX($B$2,$L3-(SUM($G3:G3)+($D$2-COLUMNS($G3:H3))*$C$2)),MIN($C$2,$L3-(SUM($G3:G3)+($D$2-COLUMNS($G3:H3))*$B$2)))))[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]



Paste the G3 formula in G3. Then paste the H3 formula in H3, then copy H3 across to K3. Then copy G3:K3 and paste them down the column as far as you need. The #NUM ! values in row 6 indicate that there is no possible solution.

As far as the algorithm, here's a quick rundown:

If you are selecting 5 numbers that must add up to a certain value, and you have already picked 4 of them, then the fifth number MUST be the target sum, minus the sum of the other four. Part of the H3 formula does just that, it looks to see if it's in the right column, and if so, does the subtraction.

Now for the previous 4 numbers, we have defined low and high values, B2 and C2. However, the more numbers we pick, the more constraints we have on the maximum and minimum values. For example, look at row 3. The first number picked was 11. Now we want to pick the second number. The total is 34, minus 11, leaves us with 23. Now let's assume that the 3rd, 4th and 5th numbers are all as low as possible, which is 5. 23 - 5 - 5 - 5 = 8. So although the theoretical maximum number for the second number is 25, at this point in the selection process, the actual maximum is 8. We do this using MIN(25, 8). Using a similar process assuming that the 3rd, 4th and 5th numbers are as high as possible (25), we find that the minimum value is MAX(5, -8), or 5. So we do a RANDBETWEEN(5, 8).

And we just repeat. The G3 formula calculates a RANDBETWEEN based on the number of values, the max and min values, and the target number. H3 to J3 perform the same thing, only they include the sum of the previously selected numbers so far. And the K3 formula is just the target minus the sum of the numbers chosen.

In principle, not too hard, but it is kind of tricky to incorporate into formulas. Take a look and let me know if you can't figure out the pieces.

Out of curiosity, where are you located, and what subject are you teaching?

Good luck!
 
Upvote 0
Hi @meiko87

I got your PM, and I'm replying this way since you can't receive PMs until you've posted some messages. I've resubscribed to this thread for now. Hopefully, you'll get the tag.

Your question is: why do I get a long string of the minimum value at the end of my list? The answer is basically that these are not "true" random numbers, they are constrained by the requirement that they add up to a given number. The first few in the series are pretty random, but if they start to average above the midpoint, then they don't leave as much room for the succeeding numbers. At some point, the formulas say: "I've got 2000 left and 5 numbers to choose, so they all must be 400." This effect is much more pronounced with large ranges, like yours. Maybe I could change the way they work. Instead of just checking to see how much I have left, I could readjust the boundaries as I go down the list, the first number must be between 400 and 2000, based on that the next number can be between 400 and 1900, the next one between 500 and 1950, and so on. I'd have to think about that some more. It's a slightly different way of creating some pseudo-random numbers.

As far as creating 2 decimal places, multiply the target, min, and max values by 100. Then take the resulting list and divide by 100. Voila!

If I think of a better way to create your pseudo-random list, I'll post again here.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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