Click to See Complete Forum and Search --> : Random Numbers


VEM
September 16th, 2000, 11:06 PM
heres the code:


private Sub Form_Load()
Label1.Caption = Int(Rnd * 10)
End Sub



Why is it that everytime that you load that load, label1 always = 7 or the same number, I want to randomly generate numbers!!

http://visualblind.tsx.org

d.paulson
September 16th, 2000, 11:55 PM
from msdn
Before calling Rnd, use the Randomize statement without an argument to initialize the random-number generator with a seed based on the system timer.



David Paulson

VEM
September 17th, 2000, 12:54 AM
I've tried that, it still doesn't work

http://visualblind.tsx.org

d.paulson
September 17th, 2000, 10:26 AM
Try this with a small project. Add a label an a command button to the form. Paste this code.

private Sub Command1_Click()
Label1.Caption = Int(Rnd * 10)
End Sub

private Sub Form_Load()
Randomize
End Sub







David Paulson

VEM
September 17th, 2000, 11:27 AM
no, you guys arent getting the picture, i need it on form_load nothing else

http://visualblind.tsx.org

dhstraayer
September 18th, 2000, 05:09 PM
I tried
option Explicit

private Sub Form_Load()
Randomize
Label1.Caption = Int(Rnd() * 10)
End Sub



on a simple form with a single default-named label, and it worked fine. Both from the development environment and compiled into an exe.
Does it work differently on your system?
(For more information about random number generation, see Knuth, Vol III I believe)


Dave Straayer
Varatouch, Inc.

VEM
September 18th, 2000, 07:35 PM
Ok, thank you

http://visualblind.tsx.org