Pregunta

How to display the outcome of throwing a dice with equal probability of 1,2,3,4,5,6 ? Random no does not display with equal probability.

Thanks in advance.

¿Fue útil?

Solución

If you have a reasonably good PRNG (pseudo-random number generator), you should be able to do something like (where % is the modulo operator):

print( good_prng() % 6 + 1 )

Some basic PRNGs aren't very random in the lower order bits. Without knowing what language and PRNG you're using, it's hard to say if this is the reason for what you're observing.

In Python (asked for in comment):

import random
print( random.randint(1,6) )

Python's random module uses a Mersenne twister, which is a very good PRNG.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top