+ Reply to Thread
Results 1 to 2 of 2

Generate random list of numbers with constraints and targets

  1. #1
    Registered User
    Join Date
    03-01-2020
    Location
    Australia
    MS-Off Ver
    MS 2016
    Posts
    3

    Generate random list of numbers with constraints and targets

    Hi Community,

    Looking for assistance for a code/set of formulas that can be used to generate a list of numbers that all must have a minimum and maximum (randbetween). The sum of the list of numbers also must equal a target.
    The solution needs to be efficient / low process and dynamic. The list must be able to auto-generate new sets of numbers (as they will feed into a monte-carlo simulation), with number of cells in list a variable input. I haven't worked much with macro/vba so not sure if once you've got a script whether it can run automatically in the background without needing to be re-run.

    I have got a spreadsheet attached with an approach i came across in another forum, which has somewhat improved my previous approach. However as I am now testing the use of this on a larger dataset later numbers in the sequence are being forced to exact values in order to achieve the desired sum target.

    Hoping someone may know a fix to this, or an alternative solution.

    Appreciate the help - and look forward to seeing if someone out there has a robust solution to this problem.

    Thanks,
    Chris
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor Hydraulics's Avatar
    Join Date
    07-15-2018
    Location
    Udine - Italy
    MS-Off Ver
    Office 365
    Posts
    370

    Re: Generate random list of numbers with constraints and targets

    I don't think there is an easy solution to this question, and it isn't a matter of formulas or VBA.

    The problem is, you are asking for a random distribution that cannot be uniform. The average of max and min values is 260, but the average of a uniform distribution would be 35000/140 = 250 (cell G2). I suppose that in a general setup these values may be even farther from each other.

    Assuming that constraints cannot be violated, you may build a VBA sub that extracts 140 random numbers between max and min values, and returns a result as soon as their sum is 35000, something like

    Please Login or Register  to view this content.
    You may have to wait for a long time, though. Really, really long.

    So, something must give in, but this decision relies on you.

    HTH,

    Francesco
    Aim high or don't even try.
    ---------------------------------
    If your question has been answered, don't forget to mark the thread as SOLVED.
    If you find an answer helpful, click on the star icon at the bottom of the post.

+ 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. Replies: 2
    Last Post: 06-08-2021, 07:14 AM
  2. [SOLVED] generate random numbers in random range vba
    By hsnfifo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-20-2020, 12:59 PM
  3. Replies: 3
    Last Post: 11-26-2017, 08:58 AM
  4. Generate random numbers from a list that would equal to a given value
    By Qutaibah in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-02-2014, 09:58 PM
  5. [SOLVED] Generate Random Numbers
    By stojko89 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-09-2013, 02:49 AM
  6. generate random numbers from a frequency list
    By adeina in forum Excel General
    Replies: 11
    Last Post: 06-21-2007, 11:34 AM

Tags for this Thread

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