A dispenser can simulate dice of up to nine sides by random choice, and there are redstone circuits for simulating six-sided dice. But how do you simulate, say, ten-sided, twelve-sided or twenty-sided dice in Minecraft?
You need to create a counter that resets after n ticks, where n is the number of sides on your dice. You can see an overview of creating a counter on Wikipedia. All you need to do is add extra logic so that when the output matches n, it resets the counter to 0.
Hook up your counter to a fast clock with a switch to stop the clock to simulate rolling the dice. The number rolled will be displayed in binary.