+ Reply to Thread
Results 1 to 3 of 3

VBA Code for a Distribution

  1. #1
    Registered User
    Join Date
    10-31-2009
    Location
    S
    MS-Off Ver
    Excel 2003
    Posts
    25

    Cool VBA Code for a Distribution

    Hi,

    I am trying to create a triangular distribution function in Excel VBA with three parameters : a, b, and c. The parameters a and c are the minimum and maximum possible values, and b is the most likely value. The method is :
    Calculate d = (b-a)/(c-a)
    Generate a random number N between 0 and 1
    If N <= d, then a + (c-a)*sqr(dN) is the required random number.
    If N > d, then a + (c-a) [1 - sqr((1-d)(1-N)) is the required random number.

    Any help will be appreciated

    Moroformat
    Last edited by shg; 12-16-2009 at 02:56 AM. Reason: restore original post

  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: VBA code for a distribution

    First, verify the math in the following sample sheet. If it is correct, then we can turn this into a UDF, but I need to make sure the formula is working correctly first.
    Attached Files Attached Files
    _________________
    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
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: VBA code for a distribution

    See http://www.excelforum.com/excel-gene...generator.html.

    Note that a and b are the min and max, and c is the mode.
    Entia non sunt multiplicanda sine necessitate

+ 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