What exactly does this code mean?

Started by
32 comments, last by Shadow1234567890 21 years, 7 months ago
What about quantum theory? Isn''t it ''random''? If the universe is not deterministic, then there is some randomness, somewhere.

Cédric
Advertisement
What makes you think the universe might not be deterministic? Quanta do what they do for a reason. We may not ever understand it, but they follow RULES, and they cannot ever deviate from the rules. Therefore, simply because we can''t quantify the dynamics of their behavior, it doesn''t mean they behave randomly.

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[twitter]warrenm[/twitter]

I dunno. I feel the same as you do, but from what I''ve read, Einstein believed in a deterministic universe all his life (hence the famous quote: "God does not play with dices"), but apparently, quantum theory proves that even if we had complete knowledge of the universe, we could not predict it (or is it that we can''t get complete knowledge?)

I probably got it all backward. If you know more than I do, please, slap me on the wrists for being stupid

Cédric
I don''t know enough on the subject to make further comments, but he seems pretty adamant that his service offers true random numbers: http://www.random.org/essay.html

dMDI
"I don''t know with what weapons the third world war will be fought, but I know the fourth will be fought with sticks and stones." Einstein
Even if true randomness does not exist, we''ll never know because of the Heisenberg principle.

To generate good random number you use multiple psuedo-random sources and use a couple of the lsb from each one (they are the most random). For example, if you periodicly execute rtdsc, it''s unlikely that the last two digits will always be the same.
And if the motherboard has a thermister (thing that reads the temperature of the CPU) on it, you can use the last one or two lsb of that as random numbers too.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
MKH: You meant the MSB, right ?

Numerical Recipes, among other sources, explicitely warn against unsing the low-order bits of linear-congruential pseudorandom number generators (i.e. most rand() functions), since they exhibit comparatively less random patterns.

That''s why the code posted by the OP is preferable to using a modulo operation (which mostly works from the low-order bits).

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
I''m pretty sure that the lsb is what should be used in MKH''s post. There might be a problem with the lsb in numerical pseudo-random number generators, but if you take the last digit of precision in a numerical thermometer, it will be much more random than the first one.

Cédric
Isn''t true randomness the source for creating real artificial intelligence?

That''s why I think our brain has kind of like a source for true random events.
Mecha Engineer (Making Real Humanoid Suits)
Some more clarifications...

Almost all of random number generators found in language libraries are Linear Congruential Generators. This is a specific algorithm for generating random numbers. While it is fast, the numbers generated are sometimes not random enough for particular purposes. When looked at in a certain higher dimensional space, the numbers it generates tend to cluster about certain planes. To make matters even worse, in such generators, the low order bits are often much less random than their high order bits. When you use a modulo operation, you are effectively only taking the lower order bits to construct your random number.

Most of the time, this generator is sufficiently random... if you notice your application is starting to have predictive behaviour, you have two options:
1) don''t use modulus when creating random numbers
2) get a better generator - there are other generators that are much more random and higher performance also

Radioactive decay is not random in that that if you sit and watch a sample and plot number of decays versus time, the number of decays per unit time will exponentially drop off in a very well known manner. However, if you watch any individual atom, there is absolutely no way to tell when it will decay. There is no observation you can make that will tell you when it will decay - it is truely random, there is nothing deterministic about it. This is a big discussion in physics, whether or not there are "hidden variables" that we are unable to detect that could make this behaviour predictable - but this is considered to be far-out physics, more in the realm of philosophy by most physicists.
The Linux kernel (and I''m sure others) use times of various interrupts (don''t know precisely which, probably hd, keyboard, mouse) to add into a sort of random pool to seed generators. Quite random I''d think.

This topic is closed to new replies.

Advertisement