It is much easier with dice, you can roll a D20 then take the remainder dividing by Dn (plus one). But you must avoid modulo bias (https://stackoverflow.com/questions/10984974) and re-roll for high rolls, which may be dissatisfying to players who roll a natural 20 on their D6 throw and need to roll again.