This question may not be language specific.
- Is it possible to create a true random number ?
- If not why random number generation has to go through some algorithm, why garbage values cannot act as random numbers.
This question may not be language specific.
It can. Depending on your definition of a random number:
(source: dilbert.com)
In most applications, what you expect from a random number generator is to generate a sequence of numbers that are uniformly distributed. A garbage value does not provide this characteristic.
Is it possible to create a true random number?
If you define "truly random" as unpredictable, the question is "unpredictable by what?"
There are cryptographically secure (pseudo-)random number generators that try to hide the state of the random number generator from user-level code, that is, ideally, only kernel mode code can feasibly predict the next random number.
However, an isolated computer system (without any external input) is a deterministic finite state machine. That is, by knowing the current state of the machine, you can always predict the next state. So, if you mean "unpredictable" by a software system in general, no, you can't use a deterministic system to generate "true randomness" according to this definition.
There's another kind of unpredictability that is more philosophical. Even if you rely on external input (such as atmospheric noise or other means), are they really unpredictable? One might argue that we live in a deterministic world and like a digital computer, everything is determined to happen; so, there's no randomness. I don't have an answer for that.
By "garbage values" I presume you mean uninitialized memory. You're not going to get good distribution, and more importantly you're going to get a lot of sequences of repeated values. Getting thousands of the same number in a row would be pretty useless for most applications that require random numbers.
For a number to be a "true random number", it would have to be non-deterministic. And since pretty much everything is (probably) deterministic, there really is no such thing as a random number. Mixing of atmospheric noise is probably the closest you can get at this point.
Garbage values are unpredicted, and you can't make any assumptions on them.
If you want a true random number, your algorithm would have to involve some "real-world" variables (e.g, the CPU temperature, fan speed, environmental noise..). Otherwise, your "random" values, would be very predictable.
There is no known "true" random number generator (as of now), but we do have pseudo random number generators, which generate number which can act as random numbers for "practical" purposes.
Computers are deterministic and can only generate pseudorandom numbers, unless they rely on some external stochastic process.
A pseudorandom number generator forms a sequence, which sooner or later is going to repeat.
Of course, very long sequences may be practically indistinguishable from 'truly random' numbers.
A 'garbage value' might be used to seed a random number generator, but then the question would be 'what range of values are being used for a seed?
It may introduce predictability, since we know some pseudorandom number generators produce the same sequence when seeded identically.