|
-
Jun 26th, 2000, 12:47 AM
#1
Thread Starter
Addicted Member
Ok some guys helped me with my contol problem, thanks but now that i have got that out of the way, i have a random image appear when the program opens, but it is always 35 (out of 50) then i decided to add a button to continue putting down images, just to see if it was always 35 bieng chosen, it wasnt, but there is a distinct pattern, the random code chooses 35, 26, 28, 14 .........and so on, in the same exact order every time, here is my code, why is it doing it?
Private Sub Command1_Click()
Random = Int(Rnd * 50)
MsgBox "" & Random
rw(Random).Visible = True
rw(Random).Left = 120
rw(Random).Top = 240
End Sub
-
Jun 26th, 2000, 12:52 AM
#2
Member
err....
okay i know how to stop it, but im not too sure on why it is hapening, to stop it put this code in
Code:
Private Sub Form_Load()
Randomize
End Sub
this will seed the random numbers by using the pc's internal clock, whtaever that means 
Hope it helps
Cease
-
Jun 26th, 2000, 12:57 AM
#3
Thread Starter
Addicted Member
thanks!
yes that definitly helped, thanks!
-
Jun 26th, 2000, 12:58 AM
#4
Member
You should use Randomize statement if you need completely randomly generated numbers ench time
you start your program.
You just put Randomize anywhere before Rnd function and there will be no pattern in generated numbers.
Like this:
Private Sub Command1_Click()
Randomize 'you can put it anywhere between Sub and
'End Sub before Rnd function is called
Random = Int(Rnd * 50)
MsgBox "" & Random
rw(Random).Visible = True
rw(Random).Left = 120
rw(Random).Top = 240
End Sub
Hope this helps,
Celery
-
Jun 26th, 2000, 01:33 AM
#5
New Member
What happens is that the random numbers are always generated with a seed number on which they base the number generation.
Without the randomize statement, the initial seed number is always the same. The randomize statement uses the system timer as the default for the initial seed number (which is the number of seconds which have elapsed since midnight).
If you prefer, you can set the seed number with the statement
Randomize[seed]
-
Jun 26th, 2000, 02:06 AM
#6
Smie, one small thing you might want to do is to set the Left and Top of the image before you make it visible.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|