
-----------------------------------
tupac
Tue Mar 28, 2006 2:26 pm

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

-----------------------------------
codemage
Tue Mar 28, 2006 2:34 pm


-----------------------------------
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
Tue Mar 28, 2006 2:46 pm


-----------------------------------
it says "rand" is not a defined function  :?

-----------------------------------
GlobeTrotter
Tue Mar 28, 2006 6:44 pm


-----------------------------------
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
Tue Mar 28, 2006 11:52 pm


-----------------------------------
nvm, i figured out an algorithm that works.
thnx for all the help :D

-----------------------------------
codemage
Wed Mar 29, 2006 12:33 pm


-----------------------------------
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:


Public Function Rand(Low As Long, High As Long) As Long
  Rand = Int((High - Low + 1) * Rnd) + Low
End Function


-----------------------------------
tupac
Wed Mar 29, 2006 4:04 pm


-----------------------------------
yea, mine looks something like that, thnx pple  :)
