This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date/Time class...?

 
Justin Porter
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Igor Stojanovic
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Igor
[ February 18, 2005: Message edited by: Igor Stojanovic ]
 
Justin Porter
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! That definitely helps!
 
Justin Porter
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1646
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic