1

I have been following the tutorial at Codecademy

I see that, as part of the process of creating a virtual die we multiply 'a random number between 0 and 1' by 6 to give us a random number between 0 and 6.

Could you break this logic down and explain why this works?

In short I am looking at this answer and asking for a nice simple explanation for why that works.

JW01
  • 123
  • fyi - I have come accross a follow-up on the codecademy site that outlines the methodology in further detail and in a clear and simple manner: http://www.codecademy.com/courses/primitives-development-course/5?curriculum_id=4f4bdd96848740000300026a#!/exercises/0 (It is less assumptive but still does not try to prove it mathematically ) – JW01 Dec 17 '12 at 21:07

2 Answers2

3

The minimum of the random number is zero. $0*6=0$. The maximum of the random number is one. $1*6=6$. the numbers were uniform from the minimum to the maximum, and they still are.

Ross Millikan
  • 374,822
2

Let $X$ be a random number uniformly distributed in $[0,1]$. This means that:

$$\text{for any } x \in [0,1], P(X \leq x) = x$$

Now observe that, for any $x \in [0,6]$,

$$P(6X \leq x) = P\left(X \leq \frac{x}{6}\right) = \frac{x}{6}$$

This means that $6X$ is uniformly distributed in $[0,6]$. Observe that

$$P(6X \leq x) = \int_{0}^{x}{\frac{1}{6}dx}$$

In other words, $6X$ has constant density 1/6 in $[0,6]$. That's why it's called a uniform distribution.

madprob
  • 2,865
  • Thanks for the answer. Its still all a bit terse. But I guess that's not your fault - I shall have to learn more about the language of maths to grok it. – JW01 Nov 20 '12 at 00:19