Pick Random Number from Range with a Short Dice Given a Dice of range 1...n, and an integer range of 1...X, where n is less than X.
What is the minimum number of dice rolls you need to fairly pick a random number from the integer range 1...X?
[For example, a dice of 6 sides and a range of 1 to 10.  The minimum number of rolls for a fair random number is 5 rolls, (you would sum all the roll values then divide by 5).] <- bad example, kept here for posterity.
 A: Averaging the rolls does not give a uniform distribution, as can be seen in the example of two six-sided dice. Instead, the standard procedure to roll a number between 1 and $x$ with an $n$-sided die is:


*

*Roll $k$ times, where $k$ is any natural number such that $n^k\ge x$. From each roll subtract 1 so that the numbers lie between 0 and $n-1$ inclusive. Define $D=\lfloor n^k/x\rfloor$.

*Interpret the sequence of numbers thus obtained as a base-$n$ number $r$. Compute $\lfloor r/x\rfloor$. If this is at least $D$, restart the process, else $(r\bmod x)+1$ is uniformly distributed between 1 and $x$ inclusive.


It may be desirable to make $k$ one more than the minimum possible for it to reduce the chances of rejection.
A: If you roll a die with $n$ faces $k$ times, there are $n^k$ possible outcomes. Assuming that the die is fair, these outcomes are equiprobable.
We need some way to assign a number from $1$ to $X$ to each outcome. The number of outcomes assigned to each number from $1$ to $X$ must be the same for all these numbers, that is, $X/n^k$. So $n^k$ must divide $X$. The minimum value for $k$ is that $n^k$ divides $X$. This is not always possible, though. 
It is possible only if every prime factor of $X$ divides $n$.
For example, if $n=6$ and $X=8$, since $6=2\cdot 3$ and $8=2^3$, you need to roll the die three times, because $6^3$ is the least power of $6$ that is a multiple of $8$. If $X$ is $10$ is not possible, because $5$ is a prime factor of $10$ and no power of $6$ is a multiple of $5$.
If you have dices with different number of faces, you can optimize the process a bit. With common dices (4,6,8,10,12 and 20), $X$ can't have a prime factor different from $2$, $3$ or $5$.
A: The real answer came already from ajotatxe in the comments: There is no possible way to do this if $X$ has a prime factor that $n$ does not contain. No matter how many times ($k$) you make throws, you cannot put the resulting, equally probable $n^k$ sequences into $X$ bins with equal number of sequences in each bin.
What I like to elaborate on are 2 more things:


*

*The misconception shown in the example, and 

*a way to do this, even if it might in theory take an unbounded number of throws.


1) Throwing a 6-sided dice will on average give you a $3.5$. If you throw one a hundred times, you are much more likely to come up with a sum near $350$ thnt with a sum near $100$ or $600$, the minimal and maximal values. That's because for a sum of $100$ all $100$ throws must be $1$, an obviously very unlikely outcome, where for a sum of $350$, you can have lots of any number from $1$ to $6$.
2) What you can do in your example (n=6, X=10) is the following: Throw your dice twice, writing down the result of the first throw, and writing down an additional $0$ if you trow $1-3$ on the second throw or a $6$ when you throw $4-6$ on the second throw. It's easy to see now that if you add the two numbers (your first throw and what you wrote down as result of the second throw), that you get a number between $1$ and $12$, uniformly distributed in that range. 
If you got a number between $1$ and $10$, take this as you random number. If you get an $11$ or $12$, start over from the beginning (2 throws). This might in theory take you an unbounded number of rethrows, but in practice the probability of that goes to 0 fast.
