aspose file tools*
The moose likes Beginning Java and the fly likes True Random Numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "True Random Numbers" Watch "True Random Numbers" New topic
Author

True Random Numbers

Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
How do I generate truely generate random numbers?
------------------
What's this H2SO4 doing in my fridge?? ( thud )


By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
Grant Crofton
Ranch Hand

Joined: Nov 08, 2000
Posts: 154
Depends what you mean by truly random numbers... You can't do it on a computer for a start. Pretty much all 'random number' functions rely on pre-defined lists of numbers in some form or another. You normally have to give a seed (time in ms is often used), but if you know the seed you'd be able to work out what the number was.
Even if you had a (physical) lottery-style ball mixer, I wouldn't say that was truly random, as if you knew the exact position of every atom, and the laws of physics, you could work out what a number would be.
It isn't possible to know the exact position of every atom, so we could never do this, but it's still not truly random.
Hope that helps. G
Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
This is true. I'm looking for anything more than Pseudo-Random. The docs in the Java Visual Age mention a lot of Pseudo-Random functions that repeat and are hardily even close to random. The same numbers come up everytime I restart my program. I'm looking for something that doesn't come up with the same numbers come up everytime. This is a bit more clear?

------------------
What's this H2SO4 doing in my fridge?? ( thud )
landon manning
Ranch Hand

Joined: Nov 20, 2000
Posts: 47
Normally the way that I do a pseudo random number is by setting the seed to the system time.
For example: (Like Grant Crofton suggested)
<CODE>
Random myRandom = new Random( System.currentTimeMillis() );
</CODE>
Since your system time is *somewhat* hard to guess correctly to the millisecond, this works as a good seed for randomizing.
Hope this helps.
 
Don't get me started about those stupid light bulbs.
 
subject: True Random Numbers