+ Reply to Thread
Results 1 to 8 of 8

Excel 2007 : RANDBETWEEN with probability of being within a range

  1. #1
    Registered User
    Join Date
    07-18-2010
    Location
    Fredericksburg, VA
    MS-Off Ver
    Excel 2007
    Posts
    5

    RANDBETWEEN with probability of being within a range

    So I have the values 45 through 90. I can easily generated a number in that range with RANDBETWEEN(45,90)

    What I want to do is generated a random number in that range with the probability of it being within a smaller range inside.

    I want the number to fall between 45-90 with the following probabilities;

    45-50 = 10%
    51-65 = 30%
    66-75 = 50%
    76-90 = 10%

    Anyone know how to do this easily?

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: RANDBETWEEN with probability of being within a range

    1) Create a list in column A with 45-50 and 76-90 listed once
    2) Add 51-65 to the list three times
    3) Add 66-75 to the list 5 times
    4) Randomize the list so the numbers are in no specific order
    5) In column B, add this formula down the whole table:
    =RAND()

    Now you have a key column A of values to choose from and a random column B of precision decimal values that changes constantly.

    In D1 put this formula:
    =INDEX(A:A, MATCH(SMALL(B:B, 1), B:B, 0))


    Now you will get a random value from column A in D1 with the probability ratio you asked for.
    Attached Files Attached Files
    Last edited by JBeaucaire; 07-18-2010 at 09:41 AM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    07-18-2010
    Location
    Fredericksburg, VA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: RANDBETWEEN with probability of being within a range

    Any way to do this just with a formula? I ask this because I want to be able to easily and quickly change the ranges and probabilities without having to redo a whole column of numbers.

    Any way to do this with a macro or something of that nature?

  4. #4
    Registered User
    Join Date
    07-18-2010
    Location
    Fredericksburg, VA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: RANDBETWEEN with probability of being within a range

    By the way, thanks for your work as well. I don't mean to sound ungrateful about it at all. It works very well.

  5. #5
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,694

    Re: RANDBETWEEN with probability of being within a range

    You could use this formula

    =CHOOSE(MATCH(RAND(),{0,0.1,0.4,0.9}),RANDBETWEEN(45,50),RANDBETWEEN(51,65),RANDBETWEEN(66,75), RANDBETWEEN(76,90))
    Last edited by daddylonglegs; 07-18-2010 at 01:42 PM.
    Audere est facere

  6. #6
    Registered User
    Join Date
    07-18-2010
    Location
    Fredericksburg, VA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: RANDBETWEEN with probability of being within a range

    Wonderful. Looks like it does exactly what I want. The only question that I have, and it may be a stupid one, is where did you get these values;

    {0,0.1,0.4,0.9}

    Thanks.

  7. #7
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,694

    Re: RANDBETWEEN with probability of being within a range

    The array of values will always start with zero and then the other figures are cumulative percentages, so because you want 10%, 30%, 50% and 10% then 0.1 represents the first %, i.e. 10% and then 0.4 is 10%+30% and 0.9 is 10%+30%+50%

    so if you wanted the split to be 20%, 30%, 5% and 45%, for example, you'd use {0,0.2,0.5,0.55}

  8. #8
    Registered User
    Join Date
    07-18-2010
    Location
    Fredericksburg, VA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: RANDBETWEEN with probability of being within a range

    Outstanding. Thanks for explaining that for me. This will work wonderfully.

+ 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