ackwell / ninjabot

Ninjabot is not 'Just Another Bot'
10 stars 8 forks source link

Dice.py: Inaccurate result when in single-throw mode #65

Closed ackwell closed 10 years ago

ackwell commented 10 years ago

Doesn't take into account probability. Someone slightly less asleep than I should modify it to weight the random numbers correctly.

cyphar commented 10 years ago

... the randomness comes from random.randint(1, 6). If you start skewing (or weighing) Poisson distributed randomness, you start to miss the whole point of it.

ackwell commented 10 years ago
elif self.TYPE == self.SINGLE:
    # Just give the total (not actually very accurate)
    total = random.randint(die * self.F_LOWER_LIMIT, sides * die)

Doesn't look like random.randint(1, 6) to me. Unless my concept of probability is completely wrong, the code above is not entirely accurate.

ackwell commented 10 years ago

The problem is that it pretends it is throwing one very large die, as opposed to lots of smaller die, hence the inaccuracy. Manually 'rolling' each 'die' individually is far too slow on large roll requests.

cyphar commented 10 years ago

... are we talking about statistical or theoretical probability? If we are referring to the statistical aspects of rolling dice, you're correct -- it isn't completely accurate. However, if we assume Poisson distribution of dice rolls, that is correct.

ackwell commented 10 years ago

The former. Given the example of 2d6, it should be much more likely that a diceroll of 7 (6 possible throws) occur than that of 2 or 12 (1 possible throw).

Bloody email didn't use markup.

cyphar commented 10 years ago

Ok ... how would you like to weigh it? Halve, then skew toward 0 (using %) and then add them again? What is a safe way of skewing numbers?

ackwell commented 10 years ago

I have no idea, hence why this is an issue as opposed to already being fixed.

cyphar commented 10 years ago

From my understanding, you'd have to raise to a power and modulo it. I'm looking into it now.

EDIT: Nope. We'll just normal distribution it.