INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Visual Basic (Microsoft) Versions 5/6 FAQ

## Numbers

 Random numbers by JESTAR faq222-3198 Posted: 18 Feb 03 (Edited 18 Feb 03) This FAQ will:1) Demonstrate how to generate a single random number...2) Show you how to generate a set of random numbers...... between 2 given values.You MUST initialize the Random Number Generator BEFORE selecting the random numbers. In your Form_Load() event, simply put the word Randomize, thus:Private Sub Form_Load()    RandomizeEnd SubGenerate a single random number between 1 and xDim MyValue as IntegerMyValue = Int((10 * Rnd) + 1)   ' Generate random value between 1 and 10.Generate a random number between x and yDim MyValue as IntegerintNumber = Int((100 * Rnd) + 150)    ' Generate a random number between 150 (x) and 250 (y){Set x (the 150 above) as the lowest number. Set y (the 100 above) to the highest number - x.)Generate x random numbers between 1 and x,  store in an arrayDim MyValue(9) as IntegerDim I as IntegerFor I = 0 To 9    MyValue(I) = Int((100 * Rnd) + 1)NextThis will generate 10 random numbers, store them in an array (MyValue), with the numbers between 1 and 100.Generate x random numbers between y and z, store in an arrayDim MyValue(5) as IntegerDim I as IntegerFor I = 0 To 5    MyValue(I) = Int((70 * Rnd) + 30)Next(This will generate 6 random numbers between 30 and 70, then store them in the MyValue array.) Back to Visual Basic (Microsoft) Versions 5/6 FAQ Index Back to Visual Basic (Microsoft) Versions 5/6 Forum

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!