1

My question is essentially if:

double d = random.nextDouble() * 2 (generates a number from 0 to 1 and multiplies by 2)

is equivalent to:

random.nextDouble(2) (generates a number from 0 to 2)

I was wondering just for the theory of it. Does multiplying a randomly generated number affect its uniform distribution in any way?

gnat
  • 6,213
  • 108
  • 53
  • 73
grueble
  • 35
  • 1
  • 5
  • What programming language is this? I initially assumed either Java or C#, but neither of those seems to allow passing a parameter to `nextDouble`. – Mark Dickinson Nov 10 '12 at 19:53

1 Answers1

-1

It absolutely does.

In case you did not notice, d will always be multiple of two. while in second case number will be evenly distributed between [0,2).

Even if you multiply two truly random variable,probability distribution gets changed. See Understanding "randomness"

Community
  • 1
  • 1
Deep
  • 5,772
  • 2
  • 26
  • 36
  • 1
    I don't think this answer is accurate: if `X` is a random variable uniformly distributed on `[0, 1)` then `2 * X` is uniformly distributed on `[0, 2)`. The OP didn't specify what language, but it's quite likely that `random.nextDouble(2)` is even implemented as something very much like `2 * random.nextDouble()`. So yes, the two things are essentially equivalent. – Mark Dickinson Nov 10 '12 at 19:51
  • 1
    Absolutely. The misunderstanding here is because we're using a discrete approximate sampling (the computer's representation of floats) from what's supposed to be a continuous distribution (uncountably infinite possibilities). While the answer is technically correct for the computer implementation, it ignores the imprecision inherent in using binary to represent continuous numbers. Theoretically, there's no difference, and if you look at integral of the density function between -delta x and +delta x, it's identical in both cases. – Ben Allison Nov 13 '12 at 15:05