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. [I'm not sure if the 'random number between 0 and 1' could ever be 0 or 1](http://www.codecademy.com/forum_questions/5082ce65d7c5a802000066c2). But, either way, that was useful in helping to give me a methodology to look at the problem from a new viewpoint.2012-11-19
  • 1
    @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.2012-11-19
  • 1
    @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.2012-11-19
  • 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