|
-
Jan 5th, 2002, 06:16 PM
#1
Thread Starter
Hyperactive Member
Random Numbers
i type this:
Private Sub Form_Load()
MsgBox rnd
End Sub
each time i start the program it displays the same exact number. It isn't supposed to do that. And it didn't use to do it either.
My monkey wearing the fedora points and laughs at you.
-
Jan 5th, 2002, 06:21 PM
#2
Fanatic Member
Try this:
VB Code:
Private Sub Form_Load()
Randomize Timer
MsgBox rnd
End Sub
Randomize is a function which initialises VB's random number generator based on an argument (Timer in this case) in some way...
Digital-X-Treme
Contact me on MSN Messenger: [email protected]
[VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
/ (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]
-
Jan 5th, 2002, 06:24 PM
#3
The picture isn't missing
it is the same in debug mode since they want you to be able to test the results on any errors with the same number.
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Jan 5th, 2002, 09:02 PM
#4
rnd random a number between 0 and 1 so if you want to have a random number between 7 and 10 you will need to do :
rnd * 3 + 7
That a little tip
-
Jan 5th, 2002, 09:10 PM
#5
Member
Originally posted by DaoK
rnd random a number between 0 and 1 so if you want to have a random number between 7 and 10 you will need to do :
rnd * 3 + 7
That a little tip
Here's a full function:
VB Code:
Public Function RandInt(lowerbound As Integer, upperbound As Integer)
RandInt = Int((upperbound - lowerbound + 1) * Rnd + lowerbound
End Function
-
Jan 5th, 2002, 09:21 PM
#6
You should add Randomize in the Function
-
Jan 5th, 2002, 09:21 PM
#7
Member
Originally posted by DaoK
You should add Randomize in the Function
Like I said before, you should only call randomize when you start your program, otherwise you get a severe performace hit.
-
Jan 5th, 2002, 09:30 PM
#8
And it's should be Randomize Time or something like that someone told me to have more change to have a real Random number.
-
Jan 5th, 2002, 09:31 PM
#9
Member
Timer is the default argument for Randomize, so these two do the same thing. Trust me, I'm right, there was a thread a while back if you search for it.
VB Code:
Randomize
Randomize Timer
-
Jan 6th, 2002, 04:16 AM
#10
Addicted Member
how do u do this if you want the no between -0.1 and 0.1
-
Jan 6th, 2002, 04:32 AM
#11
PowerPoster
hi Muds
Rnd returns a number betw 0 and 1 and so u just need to multiply by the required range. U can add or subtract minor decimal roundings as required.
Regards
Stuart
VB Code:
Private Sub Command1_Click()
Randomize
Label1 = Format$(Rnd * 0.2 - 0.1, "0.000")
End Sub
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
|