Results 1 to 3 of 3

Thread: Using Rnd function on VBA in Microsoft Excel

  1. #1
    Join Date
    Jan 2012
    Posts
    26

    Using Rnd function on VBA in Microsoft Excel

    I am having some doubts over the VBA "Rnd" function about if it really generates a random number (between 0 and 1). Does this mean that after the first random number is generated, this is used as the seed for the next one and that the number sequence from then on is pre-determined. What I actually want is the VBA equivalent of the worksheet RAND() function, but I need truly random numbers, not ones that are pre-determined by what came before. So if I have the following code:
    HTML Code:
    Let i = 1 to 1000
    Range("A1") = Rnd
    next i
    Does that generate 1,000 truly random numbers or will they be in a pre-determined sequence.

  2. #2
    Join Date
    Mar 2011
    Posts
    542

    Re: Using Rnd function on VBA in Microsoft Excel

    Computers cannot give a "Truly Random" random number, just can't be done, impossible. The nice thing about the VBA Rnd function, though, is you can specify the seed by using "Randomize" like so:
    Code:
    function rand2()
    Randomize 12345
    rand2 = rnd
    end function
    Which generates random numbers based on a seed value of 12345.

  3. #3
    Join Date
    May 2011
    Posts
    523

    Re: Using Rnd function on VBA in Microsoft Excel

    As indicated, "random" numbers from the worksheet RAND() function are also predetermined by what came before; but the exact algorithm depends on your Excel version. It also appears that RNGs in the worksheet, Analysis ToolPak, and VBA each uses a different algorithm. ATP, VBA and pre 2003 worksheet algorithms are not suitable for serious simulation work.

Similar Threads

  1. Replies: 6
    Last Post: 17-02-2012, 01:18 PM
  2. Fix Microsoft Excel function Exec Error
    By Sachi Trivedi in forum MS Office Support
    Replies: 5
    Last Post: 24-01-2012, 12:51 PM
  3. Replies: 4
    Last Post: 13-02-2011, 10:37 AM
  4. Excel Function and Excel Chart Colors
    By Samarth in forum Windows Software
    Replies: 5
    Last Post: 13-01-2010, 08:16 PM
  5. Excel PERCENTILE function without 0
    By Wyvern in forum Software Development
    Replies: 6
    Last Post: 05-01-2010, 09:37 AM

Tags for this Thread

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
  •  
Page generated in 1,713,573,749.93393 seconds with 16 queries