#separator:tab
#html:true
#notetype:Basic
#tags column:3
#deck:cracked.guide::TAOCP Vol 2::3.4.1 Numerical Distributions
#columns:Front	Back	Tags
TAOCP §3.4.1 Numerical Distributions: what does it cover?	Turning uniform random numbers into other distributions: random integers in a range, general discrete distributions (including the alias method), the normal distribution via the polar method and others, and exponential, gamma, binomial and Poisson distributions.	cracked.guide cracked.guide::phase::taocp-2 cracked.guide::section::3.4.1 cracked.guide::kind::about
TAOCP §3.4.1: why does it matter?	Every simulation, game loot table and load generator needs non-uniform randomness. The modulo-bias trap for random integers is one of the most common bugs in real code.	cracked.guide cracked.guide::phase::taocp-2 cracked.guide::section::3.4.1 cracked.guide::kind::why
TAOCP §3.4.1: what traps should you watch for?	<ul><li>Using rand() % k, which is biased when the generator range is not a multiple of k.</li><li>Taking the low bits of a weak generator for small ranges.</li></ul>	cracked.guide cracked.guide::phase::taocp-2 cracked.guide::section::3.4.1 cracked.guide::kind::traps
TAOCP §3.4.1, exercise 1 (rated 10): what is it asking?	Uniform on an arbitrary interval. Quick.	cracked.guide cracked.guide::phase::taocp-2 cracked.guide::section::3.4.1 cracked.guide::kind::exercise
TAOCP §3.4.1, exercise 2 (rated M16): what is it asking?	Exact bias of turning a random fraction into an integer in [0, k). Quantifies the rand() % k problem.	cracked.guide cracked.guide::phase::taocp-2 cracked.guide::section::3.4.1 cracked.guide::kind::exercise
TAOCP §3.4.1, exercise 3 (rated 14, recommended): what is it asking?	Dividing versus multiplying to get a random integer, and which bits each one uses.	cracked.guide cracked.guide::phase::taocp-2 cracked.guide::section::3.4.1 cracked.guide::kind::exercise
TAOCP §3.4.1, exercise 5 (rated 21, recommended): what is it asking?	Sample from a mixture of simple distributions efficiently.	cracked.guide cracked.guide::phase::taocp-2 cracked.guide::section::3.4.1 cracked.guide::kind::exercise
TAOCP §3.4.1, exercise 7 (rated 20, recommended): what is it asking?	The cubes-in-boxes construction behind Walker's alias method. Implement it.	cracked.guide cracked.guide::phase::taocp-2 cracked.guide::section::3.4.1 cracked.guide::kind::exercise
TAOCP §3.4.1, exercise 17 (rated M24, recommended): what is it asking?	Distribution, generating function, mean and spread of the geometric distribution.	cracked.guide cracked.guide::phase::taocp-2 cracked.guide::section::3.4.1 cracked.guide::kind::exercise
TAOCP §3.4.1, exercise 29 (rated M20): what is it asking?	Generate n sorted uniforms in linear time without sorting.	cracked.guide cracked.guide::phase::taocp-2 cracked.guide::section::3.4.1 cracked.guide::kind::exercise
TAOCP §3.4.1, exercise 11 (rated HM27, recommended): what is it asking?	Prove that the tail steps of the normal generator produce the correct distribution. The stretch.	cracked.guide cracked.guide::phase::taocp-2 cracked.guide::section::3.4.1 cracked.guide::kind::exercise
TAOCP §3.4.1: how many exercises, and how are they rated?	33 exercises, rated 10 to HM40.	cracked.guide cracked.guide::phase::taocp-2 cracked.guide::section::3.4.1 cracked.guide::kind::exercises
TAOCP §3.4.1: what should you be comfortable with first?	<ul><li>3.2 Generating Uniform Random Numbers</li><li>Basic probability distributions</li></ul>	cracked.guide cracked.guide::phase::taocp-2 cracked.guide::section::3.4.1 cracked.guide::kind::prereqs
TAOCP §3.4.1: how should you work through it?	Implement: unbiased random integer in [0, k), the alias method for a weighted die, and the polar method for normals. Histogram each to check. Skim the more exotic distributions.	cracked.guide cracked.guide::phase::taocp-2 cracked.guide::section::3.4.1 cracked.guide::kind::approach
