+ Reply to Thread
Results 1 to 8 of 8

Generating Lots of Random Numbers

  1. #1
    Registered User
    Join Date
    10-10-2007
    Posts
    3

    Generating Lots of Random Numbers

    I need some help generating a list of random numbers from a normal distribution. I would like to write a program that will generate 1200 random numbers given user-defined mean and standard deviation parameters and then put them into a single column of cells. I have been able to accomplish the task but not in a very efficient manner. Basically, I've generated a number, put it in a cell, move down one cell generate a new number, move down one cell, etc. This is extremely time-consuming as each step causes every previous random number to regenerate. Is there a way to generate all 1200 numbers and then put them into the column all at one time?

    Thank you for any advice or suggestions.
    Last edited by VBA Noob; 10-10-2007 at 01:46 PM.

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    09-09-2005
    Location
    England
    MS-Off Ver
    2007
    Posts
    1,500
    well the easiest way is to have the addin for analysis toolpak installed and then there is an add in that does all that for you.

    Or am I missing something?

    Regards

    Dav

  4. #4
    Registered User
    Join Date
    10-10-2007
    Posts
    3

    Additional Info

    I have a workbook with seven worksheets of formulas that will draw on the random number sequence for data, plus a cover page where a variety of statistics are summarized. Effectively, I want someone to be able to review the summary stats for one sequence, and then hit one button and have an entire new sequence generated where they can view the summary stats for that sequence. And so on. I don't want someone to have to go through the Analysis Tools Random Number Generation process each and every time.

  5. #5
    Forum Expert
    Join Date
    09-09-2005
    Location
    England
    MS-Off Ver
    2007
    Posts
    1,500
    what is the code you have got so far?

    Regards

    Dav

  6. #6
    Forum Expert
    Join Date
    09-09-2005
    Location
    England
    MS-Off Ver
    2007
    Posts
    1,500
    back to the previous suggestion, you can run analysis tools from a macro, so for example if you had the mean in cell d1 and the sd in cell d2

    the following macro (which you could add as a button) would continually repopulate the range a1:a1200 every time it was run

    Please Login or Register  to view this content.
    Does that help?

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    You could use the formula

    =NORMINV(RAND(), mean, dev)

    wrapped in some VBA to recompute the 1200 values on demand, assuming you're using Excel 2003 or beyond.

    See http://www.exceluser.com/explore/statsnormal.htm

  8. #8
    Registered User
    Join Date
    10-10-2007
    Posts
    3

    Thanks

    Thank you all for your help. Dav, your code was exactly what I needed. I had been trying to do it that way, but kept failing for some reason. Thanks again.

+ 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