Author |
Message |
tupac
|
Posted: Tue Mar 28, 2006 2:26 pm Post subject: Randomization |
|
|
i was wondering, how would you randomize numbers in visual basic. i tryed to learn different algorithms, but they keep giving me the same number when i run the perogram. anyway, any help will be greatly apreciated |
|
|
|
|
|
Sponsor Sponsor
|
|
|
codemage
|
Posted: Tue Mar 28, 2006 2:34 pm Post subject: (No subject) |
|
|
Put the following line in your Form_Load:
Randomize
And then you can use
Rand(1, 10) for random integers
or
Rnd for real numbers (that you'll have to scale to suit your purpose). |
|
|
|
|
|
tupac
|
Posted: Tue Mar 28, 2006 2:46 pm Post subject: (No subject) |
|
|
it says "rand" is not a defined function |
|
|
|
|
|
GlobeTrotter
|
Posted: Tue Mar 28, 2006 6:44 pm Post subject: (No subject) |
|
|
codemage, that's not really it. The primary random functions are :
Randomize()
and
Rnd()
Randomize shoudl just go at the beginning to set the seed.
Rnd returns a random real between 0 and 1. Thus, you can create your own function to output a random integer in a given range. |
|
|
|
|
|
tupac
|
Posted: Tue Mar 28, 2006 11:52 pm Post subject: (No subject) |
|
|
nvm, i figured out an algorithm that works.
thnx for all the help |
|
|
|
|
|
codemage
|
Posted: Wed Mar 29, 2006 12:33 pm Post subject: (No subject) |
|
|
OMG, my bad. I'm accustomed to using custom modules & libs for too many of these "should be standard" libraries.
My "Rand" function is as follows:
code: |
Public Function Rand(Low As Long, High As Long) As Long
Rand = Int((High - Low + 1) * Rnd) + Low
End Function
|
|
|
|
|
|
|
tupac
|
Posted: Wed Mar 29, 2006 4:04 pm Post subject: (No subject) |
|
|
yea, mine looks something like that, thnx pple |
|
|
|
|
|
|