How to generate a random hour?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: How to generate a random hour?

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

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