Lesson goal: Histogramming Uniform Random Numbers

Previous: Histogram Pi's digits | Home | Next: Normally distributed rnd nums

This is kind of a repeat of a past lesson, but with a much better looking histogram.

Now you try. Fix the max_number= and the hist[n] = lines.

Type your code here:


See your results here:

This code won't run! Put in something for max_number, which is the maximum random number you wish to draw from. Study the code and see how max_number is used on two occasions, once in the first for-loop that initializes the histogram arrays, and again in math.random to actually select the random nunmber. Also, fix the hist[n] = line to increment the $n^{th}$ element of array hist by one each time through the 2nd for-loop.

Run the code a few times and study the resulting histogram. What do you conclude about selecting random numbers that are claimed to be "uniform" between 1 and max_number? How has the use of the variable max_number made the code easier to change, perhaps to a different range of random numbers? Dismiss.

Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.