Consulting

Results 1 to 3 of 3

Thread: Solved: Normal distribution

  1. #1
    VBAX Regular
    Joined
    Sep 2006
    Posts
    65
    Location

    Solved: Normal distribution

    Hello

    I know that I can draw a random number from a uniform distribution using the following code:

    [vba]
    dim number as long
    dim maxval as long
    dim minval as long
    maxval = 20
    minval = 10
    randomize

    Number = Int((MaxVal - MinVal + 1) * Rnd + MinVal)
    [/vba]

    However, I would like to draw a random number from a normal distribution, where I have specified the mean and the standard deviation.
    How do I do that? Is it possible to use the data analysis tool via VBA. That is write a VBA code that returns a random number from a given normal distribution - perhaps using the data analysis tool.

    Your help is appreciated.

    Thank you
    Regards Troels

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    I think...:
    on a sheet the formula:
    =NORMINV(rand(),mean,standard_dev)
    In VBA:[vba]Number = Application.WorksheetFunction.NormInv(Rnd(), 0.55, 0.2)[/vba] where .55 is the mean and .2 is the standard deviation.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Regular
    Joined
    Sep 2006
    Posts
    65
    Location
    Great thanks a lot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •