Results 1 to 2 of 2

Thread: Rnd [-1] : what is this ?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Location
    Italy
    Posts
    12

    Rnd [-1] : what is this ?

    I have find (in Excel VBA listing) this line:

    Rnd [-1]

    without other operators. It work well without error, but what it does? I know

    a = Rnd (-1)

    but I don't know what

    Rnd [-1]

    means. Can you help me?
    Thanks in advance.
    Last edited by raoul; Sep 5th, 2003 at 05:57 AM.

  2. #2
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    Considering that it uses brackets instead of parentheses, you are probably looking at some very old code. In this case, brackets are the same as parentheses.

    Passing a negative number to Rnd causes code to ignore a Randomize command that is passed a number so that a later Rnd repeats the same series of "random" numbers. The seed doesn't get reset. You can play around with this:

    VB Code:
    1. Rnd (-1)
    2. Randomize (1)
    3. For i = 1 To 3
    4.     Debug.Print Rnd(1)
    5. Next
    6. Debug.Print " "
    Note that if you don't pass a number to Randomize, Rnd (-1) has no effect. Using the above code should have the same result as if you didn't have either of the lines before the For statement.


Posting Permissions

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



Click Here to Expand Forum to Full Width