# Why does multiplying n by a random number give you a random number between 0 and n?

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.

-
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: codecademy.com/courses/primitives-development-course/… (It is less assumptive but still does not try to prove it mathematically ) – JW01 Dec 17 '12 at 21:07

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.

-
Thanks. I'm not sure if the 'random number between 0 and 1' could ever be 0 or 1. But, either way, that was useful in helping to give me a methodology to look at the problem from a new viewpoint. – JW01 Nov 19 '12 at 3:08
@JW01: in the mathematical sense, a random in the closed interval [0,1] is at an endpoint with probability zero, so it doesn't matter. In the computer sense, often the random can be zero but never one. Sometimes you can't get zero, either. Multiplying by 6 leaves you the same place. – Ross Millikan Nov 19 '12 at 3:13
@JW01: Sorta random numbers are easy, and every computing environment gives you a rand function that is very fast. Really random numbers are hard, and if you want them you should understand a lot of issues that I don't, then ask where your random numbers come from. – Ross Millikan Nov 19 '12 at 3:18
Thanks. Yes, I heard a radio programme about random numbers and it was fascinating at how much there is to it all. – JW01 Nov 19 '12 at 3:23

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.

-
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 0:19