DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2004
    Posts
    4

    Question How to get random integer between...

    Hi guys

    I want to know how to get random integer between
    case 1 :10 & 99
    case 2 :100 & 999
    case 3 :1000 & 9999
    case 4 :10000 & 99999

    using Random class and Math.random

  2. #2
    Join Date
    Feb 2004
    Posts
    541
    The random class will generate a random number between 0 and 1. If you want to change this to another range (say between A and B) you'll do the following
    Code:
    number = A + (B * random number)

  3. #3
    Join Date
    Nov 2004
    Posts
    4
    sorry i did understand what did u write
    could u please explaine more

  4. #4
    Join Date
    Sep 2004
    Posts
    150
    I'll give you a good hint.

    Random.nextInt(max) gives you a random integer between 0 and max - 1. (it won't actually return max, keep that in mind).

    How hard would it be to set this up to give you between 10 and 99?


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