+ Reply to Thread
Results 1 to 6 of 6

Random String Generate based on Probabilities

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

    Random String Generate based on Probabilities

    Experts:

    I need some assistance with creating an Excel formula which will generate string values based on both "lookup" values and their associated probabilities. See details below (as well as attached XLS).

    Background:
    - I have 3 look-up areas covering demographics "Race" (A2:A8); "Gender" (D2:D4), and "State" (G2:G6).
    - The lists are merely for *demo* purposes. Naturally, the list (e.g., "State") may grow to include all 50 states (vs. just listing 5 US States).
    - Next to each value, I have some completely *arbitrary* probabilities. The sum of each probabilities (column B, E, and H) adds up to be 100%. Again, these % are purely for demo purposes.

    What I Want to Achieve (via e.g., Excel formula):
    - I have a matrix with 30 blank records (K2:M31).
    - Now, I want to generate some random data for each of the 3 columns (K:M); however, I want the number of random values to be generated based on their individual probabilities.

    Example:
    - In cell range M2:M31 (State), I want to generate values where "CA" will approximately occur 12 times (30 records * 40%). Now, if it turns out that "CA" would exist 11 or 13 times, that will be perfectly fine.
    - Overall though, once the matrix has been populated with 30 randomly generated values, the overall distribution of the values should somewhat be representative of the indivudal probabilties.

    My Question:
    - Is there a way I can use some RANDOM formula that populates the matrix accordingly?
    - Please keep in mind that my lookup values (columns A, D, G) could increase or decrease.
    - Also, for demo purposes, my matrix is only 30 rows deep. However, I need to be able to adjust any formulas so that I could generate a matrix with, e.g., 1000 records. Is that possible? If yes, how?

    Thank you in advance,
    EEH
    Attached Files Attached Files

  2. #2
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Random String Generate based on Probabilities

    Please try at
    O2:Q50
    =IF($J2,RAND(),"")

    K2:M50
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

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

    Re: Random String Generate based on Probabilities

    Bo_Ry:

    Wow... that's totally awesome... I truly appreciate your help on this.

    Quick follow-up questions:
    I have additional metrics (e.g., military ranks, etc.) that I also need to integrate into the list. What's the easiest way to add additional metrics into this schema? The formulas are rather long. Is there a way to simplify it by running the function one column at a time?

    Also, where do I change the value(s) if I want to increase the matrix from 30 records to, e.g., 100 records?

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

    Re: Random String Generate based on Probabilities

    The simplest way to do this is to use tables with the % values representing CUMULATIVE probabilities. For example, for gender (smallest), use

    0%
    Female
    23%
    Male
    98%
    Unknown

    If this were named GenderTbl, you could formulas like

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


    to generate random Gender values following the distribution in the 1st column of GenderTbl. There are other ways to arrange this, but they'd require using 3 arguments with LOOKUP. Tables like the one above allow for the simplest LOOKUP formulas.

    I've supplemented your workbook below.
    Attached Files Attached Files
    Last edited by hrlngrv; 11-19-2020 at 04:01 PM.

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

    Re: Random String Generate based on Probabilities

    hrlngrv - thanks for chiming in... I'll check it out. Thank you!

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

    Re: Random String Generate based on Probabilities

    hrlngrv -- wow... I really like how simple this solution is!! It's very easy to customize and add additional metrics.

    I'm loving it!!!

+ 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] Generate random values between two number and specific string
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-28-2016, 04:15 PM
  2. Generating random number string based on Alphanumeric String
    By ridemeve in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-15-2014, 04:56 PM
  3. [SOLVED] How to generate random numbers based on a condition.
    By sktneer in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-13-2013, 11:41 PM
  4. Generate random # of days based on other criteria
    By Georgia Golfer in forum Excel General
    Replies: 3
    Last Post: 09-17-2010, 02:00 PM
  5. Button to Generate Random String of Numbers
    By dlenoxx in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 02-26-2009, 06:37 PM
  6. Replies: 7
    Last Post: 09-01-2007, 04:29 PM
  7. Probabilities, random numbers and dice throws
    By Galamdring in forum Excel Formulas & Functions
    Replies: 28
    Last Post: 09-06-2005, 03:05 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