Вопрос

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.

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top