1
$\begingroup$

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.

  • 0
    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 )2012-12-17

2 Answers 2

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.

  • 0
    Thanks. Yes, I heard a [radio programme about random](http://www.bbc.co.uk/iplayer/episode/b00x9xjb/In_Our_Time_Random_and_Pseudorandom/) numbers and it was fascinating at how much there is to it all.2012-11-19
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.

  • 0
    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.2012-11-20