+ Reply to Thread
Results 1 to 9 of 9

Probability to turn i into range

  1. #1
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Probability to turn i into range

    I am trying to create a procedure to create a set of numbers based on percentages, and I just don't have the probability knowledge to get this:

    I will be iterating from i to some number (lets say 100).
    I have the following table:

    Please Login or Register  to view this content.

    How can I go through i = 1 to 100 and make sure each i has a 5% chance of being 1-49,999, a 15% chance of being 50,000 - $99,999, ect.

    Thanks
    Last edited by davegugg; 03-19-2010 at 12:08 PM.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  2. #2
    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: Probability to turn i into range

    You want a random number that 5% of the time will fall 0 to 50K, 15% will fall 50 to 100K, ...?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Probability to turn i into range

    You got it, thanks!

  4. #4
    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: Probability to turn i into range

    Using a formula,

    Please Login or Register  to view this content.
    The formula in A2:A1001 is

    =INT(LOOKUP(RAND(), {0,5,20,65,85}/100, RAND() * {50,50,100,100,150} + {0,50,100,200,300}) * 1000)

    The frequency formula at right shows the distribution for one particular set of numbers.

  5. #5
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Probability to turn i into range

    Ok, I see how that lookup function works, very nice. I am looking to run quite a few of these in vba. Is there a vba method or function that works the same way?

    This is considered a probability problem, right?

  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: Probability to turn i into range

    Try this:
    Please Login or Register  to view this content.
    Last edited by shg; 03-19-2010 at 12:24 PM.

  7. #7
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Probability to turn i into range

    Wow, outstanding!

    I'm actually a math major but never took a probability class (took two optimization research classes instead, which is how I know the Solver Add-In so well). I had to do a little research on wikipedia to understand how your function works, but I have the hang of it. You must have some formal education in math, where'd you go to school?

    Thanks a lot, you deserve 10 reputation adds for that!

  8. #8
    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: Probability to turn i into range

    You're welcome.

    Grab it again, I made a change to accommodate varying base for the arrays.

    Actually -- stand by -- both versions have an insidious error.

    EDIT: OK, fixed.
    Last edited by shg; 03-19-2010 at 12:20 PM.

  9. #9
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Probability to turn i into range

    Got it, thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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