Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vba more realistic random number generator

Tags:

random

vba

I know I can use a quasi-random number generation function/variable called Rnd. However, I've noticed that whenever I used Rnd in my userform, this sequence of numbers always show up:

first iteration: 0.705547511577606 second iteration: 0.533424019813538 ...

As a result, b/c the sequence of numbers showing up are the same every time when I relaunch the userform, it doesn't feel random. Are there other functions in the VBA function set that would make it feel more random? Thanks in advance.

like image 967
stanigator Avatar asked Dec 18 '22 06:12

stanigator


1 Answers

Try adding a single call to Randomize Timer before you do any calls to Rnd. This will seed the random number generator using the time of day.

like image 114
Travis Beale Avatar answered Jan 02 '23 19:01

Travis Beale