Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Date/Time class...?

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks! That definitely helps!
 
Justin Porter
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic