Randomizing Numbers


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Randomizing Numbers

  1. #1
    Join Date
    Mar 2005
    Location
    Ohio
    Posts
    4

    Randomizing Numbers

    Last semester for a VB class I took, we had to program a Visual Basic Tic-Tac-Toe without any help from the teacher. I established myself with getting the Tic-Tac-Toe to work, but we needed to have a random start, either computer or human first. So heres what I got.

    Dim iStart as Integer

    iStart = Rnd
    That worked just fine for the started, but now I needed to randomize where the computer started. And I found out Rnd only generates a random number 0-1. How would I generate 0-8?

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    If you look up the Rnd function in VB's online help, you'll find an example of how to generate a random number in a given range. VB's online help is also available on MSDN, so if you search Google for "rnd given range", you can find what you're looking for.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Feb 2005
    Posts
    103
    i think it is:

    edited:

    Code:
    Dim I As Integer
    Randomize
    I =  int(1 + rnd * 8)
    Last edited by XRsTX; 03-14-2005 at 12:30 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center