DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    May 2006
    Posts
    4

    Post How to generate a random hour?

    how to generate a random hour in Java?

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    generate a random int [0,24)

  3. #3
    Join Date
    May 2006
    Posts
    4
    but how?
    can you give an example please?

  4. #4
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Something like this will return you an int with a low of 0 and a high of 23:

    int hour = pickHour(24);

    Code:
    public int pickHour( int upperLimit )
    { 
        Random generator = new Random();
        return generator.nextInt(upperLimit);
    }

Similar Threads

  1. Replies: 3
    Last Post: 05-26-2006, 01:46 PM
  2. Replies: 5
    Last Post: 04-11-2006, 10:18 AM
  3. Random Numbers on button
    By daina in forum Java
    Replies: 3
    Last Post: 10-12-2005, 01:35 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