Hi, I am using a sheet which is generating a lot of uniform random numbers. Therefore, rather than using the activecell.formula = "rand()" method I have been trying to use rnd() instead. However, I am getting the feeling that the numbers generated the latter way are not completely random. I am going of the fact that I generating two functions and then plotting them, and the plots are looking quite different. Does anyone know if this could in fact be the case?
Announcement
Collapse
No announcement yet.
Using rnd() in VBA
Collapse
X

Re: Using rnd() in VBA
Yes, it is possible. From VBA HelpSyntax
Rnd[(number)]
Remarks
The Rnd function returns a value less than 1 but greater than or equal to zero.
The value of number determines how Rnd generates a random number:
For any given initial seed, the same number sequence is generated because each successive call to the Rnd function uses the previous number as a seed for the next number in the sequence.
Before calling Rnd, use the Randomize statement without an argument to initialize the randomnumber generator with a seed based on the system timer.Last edited by thomach; August 23rd, 2005, 08:32.Best Regards,
Tom

Please help Oz share knowledge among all users by posting your questions in a public forum rather than using a Private Message.

Re: Using rnd() in VBA
Without going into too much detail, my sheet generates two random numbers. The first random numbers outcome is like tossing a coin; if the result is greater than a predetermined value it generates a time value from a particular distribution, if its less it uses another distribution. The second random number is used as the value of x to get the PDF of that particular distribution.
I have used two methods of generating random numbers:
method 1:
Code:Range("Q1").Select ActiveCell.Formula = "=rand()" dblUniformValue = Range("Q1").Value Range("A2").Offset(x, 0).Select ActiveCell.Formula = "=rand()" dblX = Range("A2").Offset(x, 0).Value
Code:Randomize dblUniformValue = Rnd() Randomize dblX = Rnd()
Comment
Comment