This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Date/Time class...? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Date/Time class...?" Watch "Date/Time class...?" New topic

Date/Time class...?

Justin Porter
Ranch Hand

Joined: Nov 20, 2004
Posts: 34
New question... how can I retrieve the computer's current date/time. I want to do this to ensure completely random numbers when generating random numbers (i.e. running through 'n' number of random numbers where 'n' = day*month*year/seconds*minutes/hour or something similar.
Also, is there an easier way to get a completely random number? Is there any way to randomize the seed #? Let me know... Thanks!

Want a free iPod, digital camera, or $300 cash? Completely legit offer at <a href="" target="_blank" rel="nofollow"></a> . I am looking for referrals which is why I need YOU!
Igor Stojanovic
Ranch Hand

Joined: Feb 18, 2005
Posts: 58
Here is the code for geting current minutes on your PC:

I hope this helps you, for more info read about Calendar and Date class in java.util package

kind regards
[ February 18, 2005: Message edited by: Igor Stojanovic ]
Justin Porter
Ranch Hand

Joined: Nov 20, 2004
Posts: 34
Thanks! That definitely helps!
Justin Porter
Ranch Hand

Joined: Nov 20, 2004
Posts: 34
NOTE: Something I just found for anyone who later references this post... if you use the default constructor for the Random class (public Random()) rather than using something like (public Random(0)), it will use the current system time in milliseconds as the seed value. So randomness is nothing to worry about when using the default contstructor.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
If you need a more robust random number generator, you can use SecureRandom. It is part of Java's cryptography model, and different security providers can provide their own implementations.

When I was doing SSL programming, the SecureRandom we used would spawn several Threads and perform timing calculations for twenty seconds to generate a seed value. Others could be written to use random numbers generated by hardware. It all boils down to how random you need the numbers to be.
I agree. Here's the link:
subject: Date/Time class...?
Similar Threads
Largest/Greatest of n numbers
Random generator failing
Create Random Number
Big OOoooooo
Randomly shuffling an array.