Quote:
doug, this way the probabilites aren't equal. see julzmighty's explanation. and you made a small mistake. after -7 the range is 0..28.
Code:
(rand5()+rand5()+rand5()+rand5()+rand5() - 2) / 3
gives this distribution after 1 million runs:
{1: 6864, 2: 72170, 3: 243728, 4: 355145, 5: 243124, 6: 72255, 7: 6714}
did anyone have a thought about the one i posted earlier?
Code:
(rand5() + 5*rand5() + 25*rand5() + 125*rand5() + 625*rand5() + 3125*rand5() + 15625*rand5() - 19531) % 7) + 1
is there some hidden flaw? the result seems to be correct:
{1: 143263, 2: 142785, 3: 142579, 4: 142533, 5: 143609, 6: 142520, 7: 142711}
It looks like your method returns fairly even probabilities for each number to occur? Whats wrong with this one?