Vba is a more realistic random number generator

I know that I can use a function / variable for generating quasi random numbers called Rnd. However, I noticed that whenever I used Rnd in my user form, this sequence of numbers is always displayed:

first iteration: 0.705547511577606 second iteration: 0.533424019813538 ...

As a result, b / c, the sequence of displayed numbers is the same every time I restart the user form, it does not seem random. Are there other functions in the VBA feature set that will make it more random? Thanks in advance.

+4
source share
3 answers

Try adding one call to Randomize Timer before making any Rnd calls. This populates the random number generator using the time of day.

+10
source

I don’t know much about VB, but I think you need to sow your number generator. I think Randomize does this for VB.

+2
source

You can manually set the seed based on the time of day ... insert something like this at the top of your vba code:

 For i = 0 To (CInt(Format(Time, "ms"))) 'minutes and seconds turned to integer test_random = Rnd() Next 
0
source

All Articles