1. Reference Guide

Key Vocabulary

Term Definition Example
Random value A value selected from a set/range according to a random process. record ID 1–4
Inclusive range Both endpoints can be selected. randint(1, 4) can return 1 or 4
Possible output Any result the expression is allowed to produce. 1, 2, 3, or 4
Random choice Selects one item from a sequence. random.choice(parts)
QA simulation Repeated test runs used to exercise different program paths. random record + random API action

Python Random Quick Reference

Code Runner Challenge

Tech Talk 1 - Random SFI Record ID

View IPYNB Source
import random

record_id = random.randint(1, 4)
part = random.choice(parts)
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Reasoning Rules

  • random.randint(a, b) includes both endpoints.
  • A value can repeat on consecutive runs.
  • Seeing a few outputs does not prove those are the only possible outputs.
  • Randomly choosing a list item keeps the chosen object intact.
  • Before using a random index/range, verify every generated value is valid.
  • For reproducible debugging, a fixed seed can be useful, but normal lesson runs should demonstrate changing outcomes.

2. LxD Cycle Process

Empathize: Random code can be confusing because students may expect every result to appear once before a repeat, forget whether endpoints are included, or use a range that can generate invalid values.

Define:

  • POV: CSP students need to reason about every possible random output before using randomness in a program, because testing only one run does not prove a random algorithm is correct.
  • Learning Goal: Students will generate random integers, select random list items, identify possible results, and use random values in a repeatable backend QA workflow.

Ideate:

  • HMW Question: How might we use randomness to test different SFI automotive records and backend actions without accidentally generating invalid choices?
  • HMW Question: How might we verify a random expression by reasoning about its full set of possible outputs?
  • Activity: Generate record IDs, choose structured part records, route random API actions, then build a reusable QA simulator.

Prototype & Test: Run each example multiple times, record the outputs you observe, then explain the complete set of outputs that are possible even if a particular value does not appear during your tests.


3. College Board Requirements

AP CSP Topic 3.15: Random Values asks students to write expressions that generate possible values and evaluate expressions to determine all possible results. The exam reference sheet uses RANDOM(a, b), which returns an integer from a to b, inclusive.

Connect the pseudocode to Python:

College Board pseudocode Python
RANDOM(1, 4) random.randint(1, 4)
possible outputs: 1,2,3,4 possible outputs: 1,2,3,4
each execution may differ repeated Python runs may differ

Python also offers random.choice(list), which is useful for choosing one complete record from structured test data.

College Board Pseudocode

AP CSP uses RANDOM(a, b) in its pseudocode. It returns a random integer from a through b, inclusive.

Random Values: College Board vs Python

College Board pseudocode Python
RANDOM(1, 4) random.randint(1, 4)
list positions begin at 1 Python list indexes begin at 0
LENGTH(parts) len(parts)
parts[index] parts[index] after adjusting for indexing

SFI QA Selection in College Board Pseudocode

Code Runner Challenge

Popcorn Hack 1 - Random SFI Record Number

View IPYNB Source
recordIndex ← RANDOM(1, LENGTH(parts))
actionNumber ← RANDOM(1, 4)

selectedPart ← parts[recordIndex]

IF (actionNumber = 1)
{
    DISPLAY("GET/search")
}
ELSE
{
    IF (actionNumber = 2)
    {
        DISPLAY("POST/create")
    }
    ELSE
    {
        IF (actionNumber = 3)
        {
            DISPLAY("PUT/update")
        }
        ELSE
        {
            DISPLAY("DELETE/remove")
        }
    }
}
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Possible Results

If LENGTH(parts) = 3:

  • recordIndex can be 1, 2, or 3.
  • actionNumber can be 1, 2, 3, or 4.
  • There are 3 Γ— 4 = 12 possible record/action pairs.
  • A pair may repeat on consecutive runs.

Python Equivalent

Code Runner Challenge

Tech Talk 2 - Random SFI Part

View IPYNB Source
selected_part = random.choice(parts)
selected_action = random.choice([
    "GET/search",
    "POST/create",
    "PUT/update",
    "DELETE/remove"
])
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Pseudocode Check

Before running your simulator, choose one possible recordIndex and actionNumber, trace the pseudocode by hand, and predict the displayed action. Then compare that reasoning with your Python implementation.


4. Lesson Plan

Learning Objective: Generate random values in Python, determine every possible result, and apply randomness to backend-style testing.

Success Criteria: You can choose a valid random range, explain whether endpoints are included, distinguish random choice from guaranteed rotation, and use random results safely in program logic.

Lesson Theme β€” SFI Backend QA Test Garage

Theme: You are a QA engineer stress-testing an SFI automotive safety-spec backend.

The lesson keeps one story from start to finish:

  • Records: SFI automotive components.
  • Random record selection: chooses which part gets tested.
  • Random API action: chooses search, create, update, or remove behavior.
  • Existing spec numbers: create realistic duplicate conditions.
  • Repeated runs: exercise different backend paths.

Randomness is not added just for entertainment. It represents a real testing strategy:

β€œCan the backend handle many valid combinations of records and actions without producing an invalid state?”

The final simulator combines the full theme into repeated QA runs.

Teaching rhythm

Pause for each Popcorn Hack during the lesson: give students about two minutes to predict, edit and run the nearby code, then ask a partner to explain the result before continuing. Students copy their work and visible output into their own notebook after the live check. Save the independent Homework Hack for after class.

Tech Talk (short segments between checks)

Python’s random module provides several ways to generate random behavior:

Python Purpose Example
random.randint(a, b) Random integer from a through b, inclusive random.randint(1, 4)
random.choice(items) Random item from a sequence random.choice(parts)
repeated calls Independent random selections the same result may repeat

A random result is not the same as cycling through all values. Repeats are normal.


5. Code Examples

A. Simple: Random SFI Record ID

Code Runner Challenge

Popcorn Hack 2 - Random SFI Part Record

View IPYNB Source
# CODE_RUNNER: Tech Talk 1 - Random SFI Record ID

import random

sfi_record_id = random.randint(1, 4)
print("SFI record selected for QA:", sfi_record_id)
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Popcorn Hack 1: Random SFI Record Number

A backend QA script has four SFI part records numbered 1 through 4. The selected record number should be random and every valid record should be reachable.

Your finished runner should produce valid record numbers and explain why repeated values are allowed.

In class (2 minutes): Predict the first output, complete the runner, run it, then change one input and compare with a partner. Save your code and output in your personal notebook.

Code Runner Challenge

Tech Talk 3 - Random SFI Backend Action

View IPYNB Source
# CODE_RUNNER: Popcorn Hack 1 - Random SFI Record Number

import random

record_count = 4

# Build and test your solution below.
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

B. Random Choice from a List

Instead of choosing only an ID, select one complete SFI part name from a sequence.

Code Runner Challenge

Popcorn Hack 3 - Random SFI API Test

View IPYNB Source
# CODE_RUNNER: Tech Talk 2 - Random SFI Part

import random

sfi_parts = [
    "Replacement Flywheels and Clutch Assemblies",
    "Multiple Disc Clutch Assemblies",
    "Racing Flywheel Record"
]

selected_part = random.choice(sfi_parts)
print("SFI part selected for testing:", selected_part)
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Popcorn Hack 2: Random Structured SFI Car Part

The backend stores SFI automotive records as structured data with product name, category, and spec number.

Randomly select one complete record and display the selected record’s information without breaking the relationship between its fields.

In class (2 minutes): Decide what the first run should show, complete and run the code, then change one input to test the opposite case. Explain the result aloud and transfer both cases to your notebook.

# CODE_RUNNER: Popcorn Hack 2 - Random SFI Part Record

import random

parts = [
    {
        "product_name": "Replacement Flywheels and Clutch Assemblies",
        "category": "Auto Racing",
        "spec_number": "1.1"
    },
    {
        "product_name": "Multiple Disc Clutch Assemblies",
        "category": "Drag Racing",
        "spec_number": "1.2"
    },
    {
        "product_name": "Racing Flywheel Record",
        "category": "Auto Racing",
        "spec_number": "2.1"
    }
]

# Build and test your solution below.

C. Random Values Control Program Paths

A QA script can randomly choose a backend action, then route that choice through an if statement.

# CODE_RUNNER: Tech Talk 3 - Random SFI Backend Action

import random

actions = ["GET/search", "POST/create"]

selected_action = random.choice(actions)

if selected_action == "GET/search":
    print("QA test: search for an SFI part record")
else:
    print("QA test: validate an SFI part before creating it")

Popcorn Hack 3: Random SFI API Test

A backend QA system should vary both the SFI part being tested and the API action being simulated.

Randomly choose a part and an action, then route each action through the appropriate backend-style response.

In class (3 minutes): Predict two possible action outcomes, complete and run the code, then change the query or action. Share why the result changed; preserve your tested work in your notebook.

# CODE_RUNNER: Popcorn Hack 3 - Random SFI API Test

import random

parts = [
    {"product_name": "Replacement Flywheels", "spec_number": "1.1"},
    {"product_name": "Multiple Disc Clutch Assemblies", "spec_number": "1.2"},
    {"product_name": "Racing Flywheel Record", "spec_number": "2.1"}
]

actions = [
    "GET/search",
    "POST/create",
    "PUT/update"
]

# Build and test your solution below.

In-class MCQ Check

4 questions, one at a time. Answer each question, check it, then continue. At the end, copy the result line into your notebook and submission Notes.


6. Independent Homework & Submission

The three Popcorn Hacks above are live understanding checks. You are responsible for copying or preparing their code, predictions, and visible output in your personal notebook; the lesson page does not collect that work for you. Do the Homework Hack independently after the lesson.

Prepare your submission IPYNB

  1. In your portfolio, create a separate notebook under _notebooks/homework for this lesson. Keep the roughly four lesson notebooks expected for submission ready and individually identifiable; this lesson accounts for one notebook.
  2. Put this submission notebook frontmatter in a raw cell at the very top. It differs from the lesson page frontmatter above. Replace yourGithubID with your own ID:
---
layout: post
codemirror: true
title: 3.15 Random Values HW
categories: [Python]
lesson_language: Python
lesson_topic: Random-Values HW
lesson_part: interactive
lesson_type: lesson
permalink: /python/random-hw
author: yourGithubID
---
  1. Add your three in-class Popcorn Hacks with predictions and output, the MCQ result, then your independent Homework Hack and test output. Use headings to separate them. Run the notebook and publish your portfolio page.
  2. Submit the runnable Homework Hack Python code in the Code Submission form below. Put the published notebook link, your MCQ result, and brief test evidence in the Notes field. Do not paste a notebook file or Markdown fences into the code field.

Suggested Notes:

Lesson: CSP 3.15 Random Values
Notebook: <published URL>
MCQ 3.15: <paste result line>
Popcorn Hacks 1–3 completed during class and copied to notebook: yes
Homework tested: <cases or runs and observed output>

Keep the Homework Hack self-contained so the submitted code runs without the earlier lesson cells. The homework below is a written prompt and starter code to transfer into your notebook; work through it independently.

Homework Hack (independent): SFI Backend QA Simulator

Build a reusable randomized QA simulator for the SFI automotive backend.

The simulator should work with:

  • structured SFI part records,
  • multiple backend actions,
  • existing spec numbers,
  • repeated test runs,
  • and duplicate-spec handling during creation.

The final runner should clearly show which record and action were selected and what backend-style result occurred.

Copy this starter into your personal submission notebook after class. Complete it there, run multiple tests, and include the output. This is a reference block, not an in-page runner:

# Homework Hack - SFI Backend QA Simulator

import random

parts = [
    {
        "product_name": "Replacement Flywheels",
        "category": "Auto Racing",
        "spec_number": "1.1"
    },
    {
        "product_name": "Multiple Disc Clutch Assemblies",
        "category": "Drag Racing",
        "spec_number": "1.2"
    },
    {
        "product_name": "Racing Flywheel Record",
        "category": "Auto Racing",
        "spec_number": "2.1"
    }
]

actions = [
    "GET/search",
    "POST/create",
    "PUT/update",
    "DELETE/remove"
]

existing_spec_numbers = ["1.1", "2.1"]
test_count = 5

# Build and test your QA simulator below.

Grading Plan (1 Point Total)

Part Points What earns the points
Popcorn Hack 1 0.10 Valid random record IDs with correct explanation of the possible range/repeats.
Popcorn Hack 2 0.15 Random selection of a complete structured SFI record with correct displayed fields.
Popcorn Hack 3 0.20 Random part/action selection with correct action-dependent behavior.
MCQ 0.15 All questions attempted and result line included; full credit for 4/4.
Homework Simulator 0.40 Reusable multi-run QA simulator handles API actions and duplicate-spec behavior correctly.
Total 1.0 Β 

Quick Validation Checklist

  • Every generated record ID/index is valid.
  • Repeated random values are treated as normal behavior.
  • Structured records remain intact when selected.
  • Multiple API actions are exercised in the final simulator.
  • The complete possible output/range is explained.
  • MCQ result line and the published personal notebook link are ready for the Notes field.
  • Section 3 College Board pseudocode has been reviewed and compared with the Python solution.
  • Publish your notebook with submission frontmatter; submit the final Homework Hack Python code through the Code Submission form below.

7. Lesson Revisions

  • Kept one consistent SFI automotive/backend QA context across all examples and hacks.
  • Organized examples from simple random integers to structured random backend actions.
  • Added a reference guide and AP CSP alignment that connects RANDOM(a, b) to Python.
  • Added an interactive MCQ checkpoint before the final simulator.
  • Kept homework runners as starter scaffolds rather than completed solutions.
  • Placed College Board pseudocode alongside the AP CSP requirements in Section 3.
  • Placed the SFI lesson theme within the lesson plan.
  • Switched the assignment frontmatter to autograded code submission and added assignment creator UIDs.

Revision Made: Aligned the nine sections with the 1.02 lesson format and aligned submission metadata/instructions with code-based autograding.

  • Embedded the three live Popcorn Hacks beside their teaching examples; made homework a noninteractive notebook starter and documented personal notebook submission frontmatter.

8. Feedback Evidence

Feedback Received: The lesson model should include the seven core stages, an optional theme stage, required College Board pseudocode, and autograder frontmatter.


9. References

College Board. AP Computer Science Principles Course and Exam Description, Topic 3.15 Random Values and the AP CSP Exam Reference Sheet.

Python Software Foundation. Python Documentation: random β€” Generate pseudo-random numbers.

Submit Assignment

Your code will be saved as a Gist and reviewed automatically. You must be logged in to submit.

Need to update a submission later? Open the submissions dashboard.