Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Randomization
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
tupac




PostPosted: 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
Sponsor
sponsor
codemage




PostPosted: 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




PostPosted: Tue Mar 28, 2006 2:46 pm   Post subject: (No subject)

it says "rand" is not a defined function Confused
GlobeTrotter




PostPosted: 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




PostPosted: 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
codemage




PostPosted: 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




PostPosted: Wed Mar 29, 2006 4:04 pm   Post subject: (No subject)

yea, mine looks something like that, thnx pple Smile
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: