+ Reply to Thread
Results 1 to 11 of 11

Generate random values that are a function of % calculations

  1. #1
    Forum Contributor
    Join Date
    08-06-2018
    Location
    Virginia
    MS-Off Ver
    2019
    Posts
    342

    Generate random values that are a function of % calculations

    Experts:

    I need some assistance with generating some *random numbers* for four (4) metrics. However, the random numbers are a functions of several % calculations.

    The four metrics are (I'm using acronyms for demo purposes only):
    "A"
    "B"
    "C"
    "D"

    Also, for each of the four metrics (A:D), I have calculations for 16 systems (1:16).

    At this moment, I recommend to open the attached XLS... I think it'll help to better follow along w/ the % calculations:

    Example Data:
    - I have the 4 metrics (A:D) in cells A3:A6
    - I have example data (25, 49, 21, 42) in cells B3:B6
    - Now, cells A11:A14 shows the calculations/functions for the four metrics.
    - For instance, the 1st metric = "A/B". Thus, once I divide 25 by 49, I get 51%... check on the % value in B11.
    - Alternatively, the 2nd metric = "C/D". Thus, once I divide 21 by 42, I get 50%... check on the % value in B12.
    - Similarly, 3rd metric = "A/D" (60%) while 4th metric = "C/A" (84%).
    - Again, the values in cells B3:B6 are sample values.

    What I need some help with:
    - Now, for cells C3:Q6, I do NOT have any sample data.
    - So, I want to populate C3:Q6 with *random* data.
    - The random data, however, must give me the % values (which I do have) listed in C11:Q14.
    - I learned it is easy to generate the 1st metric. That is, I used, e.g., =Randbetween(10,99) in cell C22:Q22.
    - Next, using simple multiplication, I chose formula "=C11*C22" to populate row 21.
    - Thus, in my temporary validation section (rows 27 through 32), row 29 shows the correct output. That is, % values in row 29 match those of row 11...
    - However, once I continue on to derive at some of the other random values, my existing percentage calculations in rows 29:32 no longer match those in rows 11:14.

    My question:
    Is there a way to use formulas to derive at the correct random values (in rows 21:24) so that all of my calculations in rows 29:32 match the required % values listed in rows 11:14?

    EEH
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,858

    Re: Generate random values that are a function of % calculations

    Algebra first, then programming. (I know, algebra isn't supposed to apply to real life).

    Set it up as a system of 4 simultaneous equations (to refresh your memory on strategies for solving systems of equations https://www.purplemath.com/modules/systlin1.htm )

    A/B=percent1 -> A=B*percent1 (this is what you have in row 21)
    C/D=percent2 -> D=C/percent2
    A/D=percent3 -> won't need this.
    C/A=percent4 -> C=A*percent4

    Basically, choose a random number for any one of the variables (you have currently chosen to choose a random number for B), then calculate the other three variables from that using the system of equations. You're choosing a random number for B, then you calculate A from B. Once you have A, you can calculate C using the 4th equation. Finally, you can calculate D from the value in C using the 2nd equation (or from A using the third equation, your choice).

    Can you handle the programming from there?
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: Generate random values that are a function of % calculations

    The values in rows 3 to 6 must be positive integers? Is there any range besides 10 to 99 for row 4 (metric B)?

    Also, your percentages are rounded. For C11:C14, C13 means A = .78 D. However, C12 means C = .69 D, and C14 means A = C / .88. Perform some substitutions: .78 D = C / .88, so C = (.78) (.88) D = .6864 D . 0.6864 is close to 69%, but not exact.

    If you want smallish integers which produce metrics close enough to the targets, you'd be better off with a NONSTOCHASTIC approach.

    For example, define the name B referring to =ROW(INDEX($1:$1048576,1,1):INDEX($1:$1048576,99,1)). That makes B the array {1;2;3; . . . ;97;98;99}. Then in C4, enter this array formula monstrosity.

    C4:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    This is the smallest integer in B for which the various ratios of integers in C3:C6 rounded to 2 decimal places are effectively equal to the percentages in C11:C14.

    C3:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    C5:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    C6:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Select C3:C6 and fill right into D3:Q6. When you do so, you'll find that P3:Q6 all show #N/A, which means there isn't an integer in 1 to 99 for P4 or Q4 which would combine with other smallish integers in the other cells in P3:Q6 which would produce rounded percentages close enough to those in P11:Q14.

    However, that's why one uses defined names. Change the definition of B to =ROW(INDEX($1:$1048576,1,1):INDEX($1:$1048576,199,1)). Once you do so, P4 becomes 110 and Q4 becomes 103.

    The main thing to note is that if all cells in B3:Q6 must be integers, and the percentages are rounded, so integers would produce percentages within 0.5% of the percentages shown, then this is a relatively simple linear programming problem rather than a stochastic simulation problem.

  4. #4
    Forum Contributor
    Join Date
    08-06-2018
    Location
    Virginia
    MS-Off Ver
    2019
    Posts
    342

    Re: Generate random values that are a function of % calculations

    hrlngrv -- thank you for the work... I'm not entirely certain I can produce the results right now. Let me recap.

    - I copied the formula below into cell C4 with Shift+Enter:
    Please Login or Register  to view this content.
    - If so, I'm getting a "#NAME?" error at this time.
    - Just to be certain I didn't miss anything in your post, I then copied "=ROW(INDEX($1:$1048576,1,1):INDEX($1:$1048576,199,1))" into C4. It returned a "1".
    - Next, I copied the remaining 3 formulas into C3, C5, and C6. All of the returned values are binary though.

    If a binary response is intended then I must have missed something in my original post. Ultimately, here's what I'm trying to achieve:
    - First, see cells B3:B6. Here, I have some integer values (25, 49, 21, and 42).
    - For this example, I want all values in C3:Q6 also to be integer values.
    - Ideally, I started with random values between 20 and 99. However, rand values between 20 and 500 are ok, too.

    Any additional thoughts on how I can achieve the population of C3:Q6 with (rounded to 0 decimals) integer values between 20 and 500?

  5. #5
    Forum Contributor
    Join Date
    08-06-2018
    Location
    Virginia
    MS-Off Ver
    2019
    Posts
    342

    Re: Generate random values that are a function of % calculations

    MrShorty - thank you for the URL... I will look into it.

    For testing purposes, I added the following formulas into C21:C24, respectively:
    =C11*C22
    =RANDBETWEEN(20,99)
    =C21/C24
    =C21*C14

    Now looking at the % validations in rows 29:32, the only ones that are correct are those for metric A in row 29. What did I miss?

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,858

    Re: Generate random values that are a function of % calculations

    Using my approach, your formulas for C and D (rows 23 and 24) look wrong. From the system of equations, C=A*percent4 which is =C21*C14. Then D=C/percent2 which is =C23/C12.

    One observation I just made is that my approach will only yield integers for B (RANDBETWEEN() can only return integers). I didn't understand from the OP if integers are required or not. If you need A B C and D to be integers, then you will be better off using hrlngrv's approach. If integers are not required -- if A B C and D can be reals -- then I would probably replace B (C22) with =20+79*RAND() so that it, too, can be real and not just integers.

  7. #7
    Forum Contributor
    Join Date
    08-06-2018
    Location
    Virginia
    MS-Off Ver
    2019
    Posts
    342

    Re: Generate random values that are a function of % calculations

    MrShorty - thank you for the prompt response. Your solution works perfectly! Thousand thanks!

  8. #8
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: Generate random values that are a function of % calculations

    You must also define the name B. Don't enter its definition in C4. It does nothing useful there.
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    08-06-2018
    Location
    Virginia
    MS-Off Ver
    2019
    Posts
    342

    Re: Generate random values that are a function of % calculations

    hrlngrv - I downloaded the XLS but received only "#Name?" errors. See attached JPG.
    Attached Images Attached Images

  10. #10
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: Generate random values that are a function of % calculations

    I reopened my copy, and it also had problems with the name B. I've fixed it.

    I embellished it by displaying the definition of B in the worksheet, and that required changing to .XLSB file format to be able to use and save XLM functions.
    Attached Files Attached Files

  11. #11
    Forum Contributor
    Join Date
    08-06-2018
    Location
    Virginia
    MS-Off Ver
    2019
    Posts
    342

    Re: Generate random values that are a function of % calculations

    Looks good to me... thank you for providing the alternative solution. Appreciate your help on this activity.

+ 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. RANDOM function to generate teams with an exception
    By iiMike in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-19-2019, 11:08 AM
  2. Using Random function and Vlookup to generate a time
    By FerociousCamel in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-06-2018, 08:15 PM
  3. [SOLVED] Random Generate values of a column
    By jrable in forum Excel General
    Replies: 12
    Last Post: 11-14-2014, 02:39 PM
  4. Function to Generate Random Numbers and Letters
    By jason_kelly in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-14-2010, 03:39 PM
  5. Need to generate random values from a list
    By Sumeet Benawra in forum Excel General
    Replies: 2
    Last Post: 07-13-2006, 07:15 AM
  6. generate a random number and use if function to generate new data
    By Dogdoc1142 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-25-2006, 10:50 PM
  7. Generate random numbers between two values and with a given mean
    By pinosan in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-07-2005, 10:06 AM

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