What is the difference between sample space and random variable? I was going through this article and, on this page, I encountered the definition of a random variable and a sample space. According to this page:

A random variable is a set of possible values from a random experiment.

It then takes the example of flipping a coin, defines $Heads=0$ and $Tails=1$, and says that $X = \{0, 1\}$ is a random variable.
Next, it defines sample space as

A random variable's set of values is the sample space.

It then takes the example of throwing a dice, and states that the sample space is $\{1, 2, 3, 4, 5, 6\}$.
So, both terms are defined to be a set of outcomes for an experiment and, as a result, I got confused and couldn't differentiate between them. 
What is the difference between sample space and random variable?
I've consulted WIkipedia too and although I can understood the article on Sample Space but the article on Random Variable appears too technical and I couldn't comprehend it.
 A: From statistical inference by Casella and Berger, 

Definition 1.1.1 The set, $S$, of all possible outcomes of a particular experiment is called the sample space for the experiment.

So sample space can be thought of as all possible observations one could make from a particular experiment. A sample space for a coin toss is a set $\{H, T\}$; a sample space for rolling a six-sided die is a set $\{1, 2, 3, 4, 5, 6\}$.

Definition 1.4.1 A random variable is a function from a sample space
  $S$ into the real numbers

so random variable can be thought of as a function. The notation used for random variable is an uppercase letter. So if we have a random variable that maps sample space to real numbers, we have 
$$X: S \to \mathbb{R}$$
No one really expresses random variables this way; instead, it's often denoted as $X$. 
If that random variable $X$ is a set of possible values from a random experiment, then 
$$X: S \to S$$
so random variable is an identity function. 
A: A sample space is the SET of values a random variable can take. 
You can think of random variable as an unopened box. This unopened box contains each member of the sample space with some probability. 
In your example of a dice roll, the sample space is {1,2,3,4,5,6}. The random variable that represents a roll of the dice has a probability of 1/6 of taking on each of these 6 values.
A: Amazonian's answer is wrong. The sample space IS NOT the set of values a random variable can take. The sample space is the domain upon which a random variable is defined. The example Amazonian gave is one example of a random variable whose values happen to be the elements in the sample space.
A random variable is a function that assigns a value to every element in the sample space. There is nothing stopping you from defining a random variable X on the sample space S = {1, 2, 3, 4, 5, 6} where X = 10 * s for s in S. Then the values that X can take are {10, 20, 30, 40, 50, 60}.
A: When the sample space consists

*

*exclusively of real numbers (as in your examples),

there is no difference between the sample space and the random variable.

The difference arises in other situations, because
            the sample space may be a set of arbitrary elements, e.g. $\{\color{red} {\text{red}}, \color{green} {\text{green}}, \color{blue} {\text{blue}}\}$.
With such freedom of possible outcomes it is difficult to work. So someone invented to work not with arbitrary elements, but only with real numbers.
To reach it, the first thing is to map such elements to real numbers, e.g.
\begin{aligned}
\color{red}   {\text{red }}  &\mapsto 6.72\\
\color{green} {\text{green}} &\mapsto -2\\
\color{blue}  {\text{blue}}  &\mapsto 19.5
\end{aligned}
And that mapping is called a random variable.
So now there is a difference, because

*

*the sample space is $\{\color{red} {\text{red}}, \color{green} {\text{green}}, \color{blue} {\text{blue}}\}$, whereas

*the random variable is that mapping, often freely interpreted as the set $\{\color{red} {6.72}, \color{green} {-2}, \color{blue} {19.5}\}$.


Note:
Why is that mapping so important?
Because  we got rid of problems how to operate with arbitrary things — after choosing such a mapping we may perform calculation with numbers.
A: I believe the confusion comes from the choice of examples used. For sake of clarity lets use instead the example of the throw of 2 dices. Then, in that case the sample space would be: {(1,1),(1,2),(2,1),(1,3),(3,1),...,(5,6),(6,5),(6,6)}.
A random variable is just a function having this set as domain and the Reals as codomain (in more advanced statistics one could use other more abstract codomains).
So, for example, one could define a random variable as being the sum of the results of the dice. So the different result one could obtain are: {2,3,4,5,6,7,8,9,10,11,12}, and the probability of each one occurring is derived directly from the sample space and the probability associated with each element of the set (in this particular case each element has the same probability, but in general it could not be).
From a formal perspective a sample space is "more fundamental" than a random variable. There can be no random variable without the specification of the elements and its correspondent probabilities of the sample space of its domain.
From a practical perspective, a random variables give you 2 advantages over simple sample spaces:
(i) they are numerical. That means that one can represent, for example, a coin toss {H,T} into the numerical values {1,0}, and then apply all sort of numerical tools that cannot be applied over qualitative elements.
(ii) it makes easier to deal with elements with different probabilities. In the example given we easily created a distribution with different probabilities based on a simple calculation over a sample space with elements of equal probability. Trying to create the given result artificially could be confusing and laborious.
It is common to just use a random variable without the explicit specification of its sample space.
A: For flipping a coin:

*

*The sample space is {head, tail},

*the random variable is {0, 1}.

For rolling a die:

*

*The sample space is {1, 2, 3, 4, 5, 6},

*the random variable is {1, 2, 3, 4, 5, 6}, too,
because the sample space already is the set of numbers only.

In other words, the sample space is the set of arbitrary elements, while   the random variable is the set of numbers.
