Author |
Message |
tupac
![](http://compsci.ca/v3/uploads/user_avatars/4505289784b82e037a6d87.jpg)
|
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 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
codemage
![](http://usera.imagecave.com/codemage/codemage-small.gif)
|
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). |
|
|
|
|
![](images/spacer.gif) |
tupac
![](http://compsci.ca/v3/uploads/user_avatars/4505289784b82e037a6d87.jpg)
|
Posted: Tue Mar 28, 2006 2:46 pm Post subject: (No subject) |
|
|
it says "rand" is not a defined function ![Confused Confused](http://compsci.ca/v3/images/smiles/icon_confused.gif) |
|
|
|
|
![](images/spacer.gif) |
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. |
|
|
|
|
![](images/spacer.gif) |
tupac
![](http://compsci.ca/v3/uploads/user_avatars/4505289784b82e037a6d87.jpg)
|
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 ![Very Happy Very Happy](http://compsci.ca/v3/images/smiles/icon_biggrin.gif) |
|
|
|
|
![](images/spacer.gif) |
codemage
![](http://usera.imagecave.com/codemage/codemage-small.gif)
|
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
|
|
|
|
|
|
![](images/spacer.gif) |
tupac
![](http://compsci.ca/v3/uploads/user_avatars/4505289784b82e037a6d87.jpg)
|
Posted: Wed Mar 29, 2006 4:04 pm Post subject: (No subject) |
|
|
yea, mine looks something like that, thnx pple ![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
|