aspose file tools*
The moose likes General Computing and the fly likes Random number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » General Computing
Bookmark "Random number" Watch "Random number" New topic
Author

Random number

Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1533
How it is generated by a machine?


Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39834
    
  28
There are all sorts of ways a machine could create a random number: thermal noise in a resistor, nuclear decay (recording the order of hits between two Geiger counters), rolling balls like a roulette wheel. Lots of others.
A computer cannot create a random number. If you look through the code for the java.util.Random class, by unzipping the src.zip file in your Java™ installation folder, you can see how the Random class attempts to get close to randomness.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4465
    
    8

Have a search for "pseudo-random numbers". Basically, computers don't generally generate truly random numbers. Instead they use an algorithm that generates numbers that appear to be random, and are close enough to random for most purposes.
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1533

What is not being random and appearing to be close enough to be random?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4465
    
    8

Akhilesh Trivedi wrote:
What is not being random and appearing to be close enough to be random?

It's not random because it's entirely predictable - it's the result of an algorithm. Therefore, by definition, it isn't random.

It's close enough to random because it's very difficult to tell the difference between the output of a good pseudo-random generating algorithm and true random numbers. So unless you have a requirement for the numbers to be truly random then pseudo-random numbers are good enough. In most cases, apparent randomness is fine.

Use the Java Random class to print out, let's say 100 numbers. The output looks pretty random, doesn't it? You'll see some localised patterns, but then true random numbers have those as well. You need some pretty powerful mathematical tools to tell the difference.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Random number