Ludium
Sign In
Introduction to Computational Thinking and Data Science
Optimization
01Optimization Models and the Knapsack Problem02Brute-Force Knapsack and the Exponential Power Set03Greedy Algorithms: One Function, Any Definition of Best04Lambda Keys and Why Greedy Can Miss the OptimumProblem setMIT problem set
01The Knapsack Search Tree: Every Combination, 2ⁿ Nodes02Recursive maxVal: An Exhaustive Search That Beats Greedy03Memoization: Turning Slow Fibonacci into fastFib04Overlapping Subproblems and the Memoized KnapsackProblem setMIT problem set
Graph Models
01Graphs as Models: Nodes, Edges and Euler's Seven Bridges02Coding a Graph in Python: Node, Edge, Digraph and Graph03Depth-First Search for the Shortest Path in a Graph04Breadth-First Search: A Queue of Paths, Fewest Hops FirstProblem setMIT problem set
Stochastic Thinking
01Predictive Nondeterminism and the Stochastic Die Roll02Probability as Counting, and When Multiplying Fails03Simulating Rare Events: Random Seeds and Many Trials04The Birthday Problem: Formula Versus SimulationProblem setMIT problem set

Simulating Rare Events: Random Seeds and Many Trials

Why did 1,000 simulated rolls say a 1-in-7,776 event never happens, and what does random.seed do to the dice?


Finger exercises

Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.

0 / 5 passed
Exercise 1 of 5

Same seed, same rolls

Seed the generator with random.seed(0) and roll ten dice with the given rollDie() into the list first. Then seed it with 0 again and roll ten more into second. Assign both lists.

Given code — runs before yours
import random

def rollDie():
    """returns a random int between 1 and 6"""
    return random.choice([1, 2, 3, 4, 5, 6])
1
2
3
4
first = ...  # your code here
second = ...

Python runs in your browser
⌘/Ctrl + Enter runs
?
both are lists of ten rolls
?
the rolls are die faces
?
the same seed reproduces the sequence
←Previous Probability as Counting, and When Multiplying FailsNext The Birthday Problem: Formula Versus Simulation →