1

Which is more random?

rand()

OR

rand() + rand()

OR

rand() * rand()

Just how can one determine this? I mean. This is really puzzling me! One feels that they may all be equally random, but how can one be absolutely sure?!

Anyone?

Mukul
  • 355
  • 1
  • 3
  • 8
  • In that case, this question should be closed as a duplicate. – Chris Taylor Jun 22 '12 at 11:05
  • At least two reasons: (1) It was posted 2 years ago, when the site was a little more lenient with respect to the kind of questions asked, (2) it isn't a duplicate. Also, accusing the community of hypocrisy is rarely the best way to get your point across. – Chris Taylor Jun 22 '12 at 12:05

2 Answers2

8

The concept of being "more random" doesn't really make sense. Your three methods give different distributions of random numbers. I can illustrate this in Matlab. First define a function f that, when called, gives you an array of 10,000 random numbers:

f = @() rand(10000,1);

Now look at the distribution of your three methods.

Your first method, hist(f()) gives a uniform distribution:

enter image description here

Your second method hist(f() + f()) gives a distribution which is peaked in the centre:

enter image description here

Your third method hist(f() .* f()) gives a distribution where numbers close to zero are more likely:

enter image description here

Chris Taylor
  • 46,912
  • 15
  • 110
  • 154
  • So it does make sense right! It means "rand()" would result in getting the most random numbers... Right? – Mukul Jun 22 '12 at 09:16
  • The distribution generated by a call to `rand()` has higher [entropy](http://en.wikipedia.org/wiki/Entropy_(information_theory)), if that is what you mean by "more random". – Chris Taylor Jun 22 '12 at 09:19
  • Entropy is a measure of the uncertainty associated with a random variable. So yes.. That would mean the same as saying "more random". – Mukul Jun 22 '12 at 09:20
  • 1
    The key point is that the article says that antropy is **a** measure of uncertainty, not *the* measure of uncertainty. There are other measures, which will give different results. This is why I said that asking what is "more random" doesn't make sense, until you specify what you mean by "more random". – Chris Taylor Jun 22 '12 at 09:24
  • Warning: the charts may mislead; if `rand()` generates a random integer from 0 to 1000, then `rand() + rand()` has more entropy than `rand()`; it is much less even, but the values span twice the range. For example, if `rand()` is uniformly 0 or 1, then it's distribution is {1/2, 1/2} while distribution of `rand() + rand()` is {1/4, 1/2, 1/4} which clearly gives larger entropy. – sdcvvc Jun 22 '12 at 16:06
  • Yes, that's true. In a comment on another answer I mentioned that the uniform distribution has maximal entropy of all distributions *on a fixed range*. The fixed range qualification is important. This illustrates one of the difficulties of comparing distributions to see which is "more random"! – Chris Taylor Jun 22 '12 at 16:16
1

As to amount of entropy, I guess, is comparable.

If you need more entropy (randomness) than you have currently have, use cryptographically strong random generators.

Why they are comparable --- because if attacker could guess next pseudorandom value returned by

rand()

it would not be significally harder for him to guess next

rand()*rand()

Nevertheless argument about different distributions is important and valid!

Mukul
  • 355
  • 1
  • 3
  • 8
jb.
  • 23,300
  • 18
  • 98
  • 136
  • 3
    On a fixed range [0, N] a uniform distribution has the maximum possibly entropy. Any other distribution has strictly lower entropy. – Chris Taylor Jun 22 '12 at 09:16