I have a $6$-sided dice and I would like to sample integers uniformly from $0$ to $k$ with $k > 6$. I think that $k$ should be written in its binary representation. Let's say its binary representation has $n$ bits. I should then roll the dice and set rolls $1,2,3$ as corresponding to 0, and rolls $4,5,6$ as corresponding to 1. Then I should roll the dice $n$ times to get each binary bit.
If the resulting number is greater than $k$ (eg, it is 244 which has an 8-bit binary representation, but there exist 8-bit binary numbers which are greater than it), then the number should be rejected and the process should be repeated until we get an appropriate number.
Does this sample uniformly?
I think that it should. I think that this uniformly gives an 8-bit binary number because it's like we're sampling on $\{0,1\}^n$ which can be done by sampling $n$ i.i.d uniform variables for each coordinate.
However, how can it be guaranteed that the rejection part of this process makes sure that the sample will still be uniform?