The mathematician in me would like to point out that you can't get any number as there are an uncountable number of irrationals, therefore no function from a countable set (like the integers) will be onto. In layman's terms, you can't get pi from dice.
For the normal function, take a dice with an even number of sides. A "high" number (higher than the average) goes to 1, a "low" number goes to 0. Create a binary string in this manner with as many digits as is necessary so you exceed your desired count. If the number rolled falls outside the count, re-roll.
Example: I want to roll a d10 using only a d6. As 1111=15, 4 rolls will be sufficient. I roll a 6,4,5,2,4, which translates to 1101, which is 13. This is outside my range of probabilities, so I re-roll. This time I get 2,5,3,6,1, which translates to 01010, which is 6, so my final answer is 6. Though the probability of a re-roll is higher than the probability of getting any individual number, the probabilities of all the numbers are the same, which is what matters.
It's basically ed boy's system, only simplified down to base 2 so you don't have to worry about changing bases too often or anything like that.
If you have a d10, you're in luck, as there's no need for a base change. Just roll and let that be your digit. Of course, you'll wind up with a lot of re-rolls as powers of ten get really big really quickly, but it's a viable system.