Lesson 49 of 55
9 mins readPython Statistics & Random Number Generation
In Plain English
Perform data science and statistical analysis using the Statistics and Random standard libraries. Generate pseudorandom distributions and compute descriptive statistics.
Deep Dive: How It Works
Descriptive Stats: mean(v), std(v), var(v), median(v), quantile(v, 0.75).
Random Numbers: rand() generates Uniform(0,1); randn() generates Normal(0,1) Gaussian floats.
Reproducibility: Random.seed!(1234) sets the random seed for reproducible simulations.
Core Rules to Remember

Statistics Standard Library: mean, median, std, var, cor, and cov functions.

Random Distributions: rand() for uniform, randn() for standard normal Gaussian distributions.
Live Interactive Example
Hit Run Code to see it liveSummary Statistics and Random Distributions
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Output Console
Click "Run Code" to view the rendered output.
How it works: randn(1000) produced 1000 normal random numbers centered around 0.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Compute Sample Mean and Std
Import `Statistics`.
Given `vals = [10.0, 20.0, 30.0, 40.0, 50.0]`.
Print `"Mean: $(mean(vals)), Median: $(median(vals))"`.
1
2
3
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.