+ Reply to Thread
Results 1 to 11 of 11

Random numbers whose sums equals "x"

  1. #1
    Registered User
    Join Date
    06-09-2017
    Location
    Lansing, MI
    MS-Off Ver
    2013
    Posts
    12

    Random numbers whose sums equals "x"

    Is there a way to be able to have Excel generate a group of non-decimals numbers, whose total sum equals 6,000?

    For this example, let's say I want 5 random numbers that equal 6,000. I would want to be able to change up both variables at any time, however.

    Thanks,
    Chris

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,984

    Re: Random numbers whose sums equals "x"

    Is this something close?? Two formulae:
    Column A:
    =RANDBETWEEN(MAX($I$1,$I$4-(($I$3-COLUMNS($A2:A2))*$I$2)),MIN($I$2,$I$4-$I$3))

    Other columns (B-F):
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    All variables can be adjusted from the Table on the right.
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Random numbers whose sums equals "x"

    Cross-posted at https://www.mrexcel.com/forum/excel-...otaling-x.html
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,984

    Re: Random numbers whose sums equals "x"

    Oh Pooh!! Please don't waste everyone's time by cross-posting WITHOUT including links to the other thread(s).

  5. #5
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Random numbers whose sums equals "x"

    This is something I see alot of people ask for, but if you require the numbers to add up to a specific value...they arent random any more. Especially eliminating decimal values (as using decimals mean an infinite combination is possible). Are we presuming positive integers only or can we use negative numbers?

    What you are really asking for is to randomly pick 1 of the possible combinations that add up to a number.

    To explain (simplified, presuming positive integers only):

    Lets say you want me to randomly pick 2 numbers that add up to 10. I can randomly pick just about any number (random) as my first right? So I pick 7 lets say. Well there is only 1 number I can pick as my second number to satisfy the criteria which is 3...not really a random choice.

    So going back to it being "randomly pick 1 of the possible combinations that add up to a number" this then requires other criteria/considerations to determine how it picks. Lets take your request, 5x numbers = 6,000.

    You could do:
    1st number can be RANDBETWEEN(1,6000)
    2nd number can be RANDBETWEEN(1,6000-1st)
    3rd can be RANDBETWEEN(1,6000-SUM(1st,2nd))
    4th can be RANDBETWEEN(1,6000-SUM(1st,2nd,3rd))
    5th has to be 6000-SUM(1st thru 4th)

    The above creates a bias though doesnt it, since the 1st selection can always pick from a wider range of number than all those after it and the 4th number for example will never be able to pick at the highest > 6000-3 (if 1st,2nd,3rd were all =1). Then lastly the 5th value isnt really random.

    Alternatively you may be able to randomly pick which number you pick 1st, 2nd, 3rd, 4th and 5th...IE: 4th, 3rd, 1st, 2nd, 5th but this is really an illusion (presuming you generate each number in a cell of its own, than the order on sheet is just a different representation of the above)...you still have the same issue as above. With each number you generate in the sequence your options for what numbers can be used to equal your goal diminish.

    Any other criteria/considerations can drastically change things...for example someone may then say, "Well I really want the 5 largest numbers that = 6000"...now you have to generate every single combination of 5 numbers that = 6000 and rank each against the others to determine this. Thats very complex, mathematically difficult and not something Excel is good at doing.

    So if the above logic accomplishes what you aim to do great, but if what you are aiming for is more complex than you have let on, you are likely using the wrong tool for the job
    Ways to get help: Post clear questions, explain your overall goal, supply as much background as possible, respond to questions asked of you by those trying to help and post sample(s) files.

    "I am here to help, not do it for people" -Me

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Random numbers whose sums equals "x"

    The approach of generating random numbers and scaling by their sum favors mid-size numbers at the expense of small and large numbers.

    The approach described in post #5 favors large and small numbers at the expense of mid-size numbers.

    The UDF at the cross-post generates numbers with a Dirichlet distribution, the same distribution as the numbers in all 5-element partitions of the sum.
    Last edited by shg; 01-19-2018 at 02:25 PM.

  7. #7
    Registered User
    Join Date
    06-09-2017
    Location
    Lansing, MI
    MS-Off Ver
    2013
    Posts
    12

    Re: Random numbers whose sums equals "x"

    Sorry Glenn, I assumed they were two completely separate forums. I simply posted in both so I could get an answer quicker.

  8. #8
    Registered User
    Join Date
    06-09-2017
    Location
    Lansing, MI
    MS-Off Ver
    2013
    Posts
    12

    Re: Random numbers whose sums equals "x"

    Thanks for everyone's input. It gives me some things to try out.

  9. #9
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,984

    Re: Random numbers whose sums equals "x"

    They are separate fora. the point is that someone could have spent time answering on one forum, totally unaware of solutions already provided elsewhere. Most fora require/request cross-posted threads to be flagged up right at the start.

  10. #10
    Registered User
    Join Date
    06-09-2017
    Location
    Lansing, MI
    MS-Off Ver
    2013
    Posts
    12

    Re: Random numbers whose sums equals "x"

    Message received...I will remember that going forward.

  11. #11
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,984

    Re: Random numbers whose sums equals "x"

    Cheers. Hope someone has provided you with what you need.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Day counts, formulas between colums. "c" minus "f" = equals ???.
    By israelalvarado in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-28-2017, 05:58 PM
  2. [SOLVED] If cell equals "CR" then make cell to left negative and delete "CR".......
    By pasqualebaldi in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-14-2016, 07:51 PM
  3. Check if A1 equals the sum of A2+A3 display "correct" if not "Try again"
    By eatmydust in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-23-2014, 09:14 AM
  4. Replies: 4
    Last Post: 11-22-2012, 10:13 AM
  5. [SOLVED] Delete row if cell in Column N equal "Different" or Column P equals "Blank"
    By Cyberpawz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-17-2012, 08:25 AM
  6. replicatable "random" numbers for homework
    By hesprus2 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-30-2008, 11:34 PM
  7. [SOLVED] Sum is positive value or "0" value. Negative value equals "0"
    By MorTTime in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-28-2005, 08:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1