2 Comments
Apr 10, 2021Liked by Quastor Tech

Some of this is a bit subtle. The key is this observation "This function will generate a number between 0 and 24 (inclusive) with each number having an equally likely chance of being generated." You couldn't use a similar procedure with multiplier 1 (i.e. `1 * rand5() + rand5()`), in the same way that rolling two dice does not yield a uniform distribution over 1-12. The key is the choice of 5 as the multiplier. The way I think about it is if you wrote numbers in base 5, i.e. `0 1 2 3 4 10 11 12 13 14 20 ...` Then this procedure is equivalent to randomly picking the number in the ones place and then randomly picking the number in the 5s place. Thus all numbers between 0 and 100 (base 5, exclusive) are equally likely.

Expand full comment
author

Great way to think about it. Will add that to the post, thank you!

Expand full comment