Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random number: Rnd(1) repeats the rnd number series

Status
Not open for further replies.

Bresart

Programmer
Feb 14, 2007
314
ES
Hi, i have put the function Rnd(1) inside a FOR bucle for creating 9 random numbers between 1 and 46, so when bucle finish the code has created 9 random numbers.

But i have seen after several executions of the code that the 9 numbers series are repeated, keeping the order, and moreover after few code executions.

Does that has any solution? Creating randoms in real random way?

Thanks for looking.
 
You should use the randomize statement with no arguments, to inialize the random-number generator with a seed based on the system timer, before calling Rnd.

Code:
Randomize
For i = 1 To 9
 number(i) = Rnd(46) + 1
Next
 
It has fixed the problem. Thanks for the useful post Hans.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top