October 2025
Intermediate to advanced
485 pages
13h 2m
English
You’ve seen how random sampling is used in the world of pollsters. Let’s now take a look at how we can use random sampling within the world of code. We’ll begin with some examples of computing averages.
Say that we have an unsorted array containing a whole bunch of integers. To calculate the mean of these numbers, we first compute the sum of all N integers and then divide by N. Because we have to add up all N numbers, this algorithm takes roughly N steps.
With random sampling, though, we could calculate an approximate mean by picking a random sample of integers from the array and then computing the mean of that sample.
So, if our array contained 1,000,000 elements, getting the ...
Read now
Unlock full access