{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Workbook for Chapter 7 of Explorations in Computing"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Section 7.2: Numbers on Demand"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Execute these cells to initialize the notebook:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from PythonLabs.RandomLab import *"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%matplotlib tk"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### `rand` "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use the code cell below to define the function named `rand` shown in Figure 7.4 (don't forget the assignment statement on line 1). If you want to download the code from the EiC website visit `prng-v1.py`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Exercises"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T23. Call `rand` a couple of times to see that it works as expected:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T24. Initialize a number line plot:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"T25. Use a `for` loop to plot the first 50 values from the sequence that uses $a = 81$, $c = 337$, and $m = 1,000$:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"♦ In the exercises above we didn't reinitialize `x` to 0 before calling `rand` with $a = 81$, $c = 337$, and $m = 1,000$. Will `rand` return values from this new sequence, or did we need to reinitialize `x` first? Predict the values you think were generated on the first three iterations of the `for` loop, then check your answer by repeating all the exercises, except this time have the `for` loop print the value returned by `rand` instead of plotting it on the canvas."
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"♦ What will happen if we switch back to calling `rand(1,8,12)` after making 50 calls with $m = 1,000$?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}