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.
Printable View
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.
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:
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.VB Code:
Rnd (-1) Randomize (1) For i = 1 To 3 Debug.Print Rnd(1) Next Debug.Print " "
:)