DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  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.

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links