문제

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