From Random Digits to Calculator Commands
In Selecting an SRS With a Random Number Table, we used fixed-size digit groups to select roster labels. A calculator can generate those labels directly as random integers. The key rule is the same: accept a valid label that has not been selected before, and skip a label that is already in the sample.
On a TI-84, the command randInt(lower, upper) generates a random integer from the lower bound through the upper bound, including both endpoints. Adding a third argument tells the calculator how many integers to generate: randInt(lower, upper, number of draws). The particular values produced can vary from one run to another.
For example, if a roster has 24 individuals labeled 1 through 24, the command \(randInt(1,24)\) generates one label in that range. The command \(randInt(1,24,6)\) generates a list of six labels in that range. A generated label may appear more than once. The calculator is making random draws that can include repeats; the sample we build by skipping repeats is without replacement.
Some calculators display labels without leading zeros. If a roster is labeled 01 through 24, the calculator may display 4 rather than 04. These represent the same individual. Keep the roster-label correspondence clear, and do not mistake a display format for a different label.
Set the Range and Process the Results
First, make sure the sampling frame is an appropriate list of the population you want to study, as discussed in Population, Sampling Frame, and Sample. Give every individual one unique label. If there are \(N\) individuals, labeling them 1 through \(N\) is a convenient choice.
Enter the smallest and largest labels as the lower and upper bounds. These bounds are inclusive: \(randInt(1,24)\) can return 1 or 24. If your roster is labeled 001 through 180, enter the numerical bounds 1 and 180. A command with the wrong upper bound could omit roster members or generate values that do not correspond to anyone.
You can generate values one at a time or in batches. With one-at-a-time generation, use \(randInt(1,N)\), check the result, and repeat the command as needed. With batch generation, use \(randInt(1,N,k)\) to request \(k\) values. In either case, preserve the order in which values are generated.
- Accept a label if it identifies someone on the roster and has not yet been selected.
- Skip a label that has already been selected; it does not add another individual to the sample.
- Continue generating values if the requested number of distinct labels has not been reached.
- Stop as soon as the sample contains the requested number of different individuals.
If your calculator generates values using the exact roster bounds, every output will be in range. Unlike a random number table, you should not expect out-of-range values from a correctly entered randInt command. A repeated value is still possible, though, so you must check for duplicates.
A Step-by-Step Calculator Routine
Give each individual one unique label, such as 1 through \(N\).
Use \(randInt(1,N)\) for one draw or \(randInt(1,N,k)\) to generate a batch of \(k\) draws.
Accept a label that is new to the sample. Skip it if that individual has already been selected.
If the batch did not provide enough different labels, use randInt again and continue checking.
Stop when you have the requested number of distinct labels, then use the roster to find the selected individuals.
Worked Example: Selecting Five People from a Roster
Worked Example: A Neighborhood Tree Survey
A fictional neighborhood association has 24 volunteer tree monitors and wants an SRS of five monitors to answer a survey. Label the roster 1 through 24. The coordinator enters \(randInt(1,24,8)\) and gets the following possible output:
Process the values in order: Select 17 and 4. The next 17 is a repeat, so skip it. Select 23. The value 0 is outside the roster’s range, so it does not identify a monitor. A correctly entered \(randInt(1,24,8)\) should not generate 0; this value is included here to illustrate how to respond if an out-of-range value appears because of an entry or transcription error. Check the command and roster before accepting any value.
Continuing through the displayed list, select 9. The next 4 is a repeat, so skip it. Select 12. The five selected labels are 17, 4, 23, 9, and 12. Stop there.
Report the sample: The sample consists of the five monitors corresponding to labels 17, 4, 23, 9, and 12. The order records how the labels were generated; it does not change which five individuals make up the sample.
Worked Example: Continue After a Batch Has Too Few Labels
Worked Example: Sampling a Robotics Club
A fictional robotics club has 32 members labeled 1 through 32. A coordinator wants six members for a short equipment-feedback survey. The coordinator generates six values using \(randInt(1,32,6)\):
Use the batch in order: Select 8. Skip the second 8 because that member is already selected. Select 31, 14, 32, and 2. The batch has produced five different members, not six, so the coordinator must generate another value rather than count a duplicate twice.
The next command, \(randInt(1,32)\), produces 14. Since 14 is already selected, skip it and generate another value. The next command produces 19, which is new. Now the six selected labels are 8, 31, 14, 32, 2, and 19.
Explain the stopping rule: The coordinator stops after accepting the sixth distinct label. It would also be valid to generate a larger batch at the start, but any extra values after the sample reaches six are not used.
Worked Example: Labels That Include Leading Zeros
Worked Example: Selecting Equipment Records
A fictional repair shop has 180 equipment records, labeled 001 through 180. It needs a sample of four records for a routine inventory check. The calculator command is \(randInt(1,180,6)\), and the possible output is:
Process the output: Select label 5, which corresponds to roster label 005. Select 180, then skip the repeated 5. Select 73. These are three distinct records. Select 121 as the fourth distinct record, and stop. The later value 44 is not part of this sample because the requested sample size has already been reached.
Report the sample: The selected records are 005, 180, 073, and 121. Writing the roster labels with three digits makes it easy to match the calculator’s output to the roster. The calculator’s 5 is not an invalid label; it is the same numerical label as 005.
The command uses 1 and 180 as its bounds because the roster contains 180 records. If the command were entered as \(randInt(1,179,6)\), record 180 could never be selected. If it were entered with an upper bound larger than 180, some generated values would not match any record.
Why the Final Sample Is Without Replacement
The raw calculator draws may repeat because each call can produce any label in the range. But when you accept only labels not already selected, each individual enters the final sample at most once. That is what “without replacement” means here: once an individual is selected, that person cannot be selected again to fill another place in the sample.
Skipping a repeated value does not mean replacing it with a label chosen by the sampler. You simply ignore the repeat and continue to the next random draw. Do not change a repeated 8 into a 9, for example, or restart because the output seems inconvenient. Either action could make some possible samples more likely than others.
This procedure also gives each possible group of the requested size an equal chance of selection, assuming the calculator’s random integer generator treats the roster labels fairly. One way to see why is to consider the order of the distinct labels: every possible ordered sequence of different labels is equally likely. Any particular group of \(n\) individuals can appear in \(n!\) different orders, so every group has the same number of ways to be selected.
This connects the calculator routine to the definition of an SRS in Simple Random Sample Defined. The important feature is not that one selected group looks balanced or representative. It is that the selection process gives every possible group of the chosen size an equal chance.
Common Mistakes and AP Exam Tips
- Counting repeated labels twice. A sample of six individuals must contain six different individuals. A repeated calculator output is skipped, and another value is generated if needed.
- Using the wrong bounds. Check that the lower and upper bounds match the smallest and largest roster labels. The endpoints are included.
- Generating only the requested number of values. A batch of \(n\) draws can contain repeats and may therefore produce fewer than \(n\) distinct labels. Generate additional values until the sample has \(n\) different individuals.
- Changing a repeat into a different label. Do not substitute a number of your choosing. Skip the repeat and let the next random draw determine the next candidate.
- Restarting after an unwanted result. Follow the output in order. Restarting because a label is surprising or inconvenient can change the selection chances.
- Confusing the raw draws with the final sample. The list from randInt may have duplicates. The final sample consists only of the requested number of distinct labels.
- Misreading leading zeros. A calculator display of 5 corresponds to roster label 005 if labels use three digits. Use the roster to identify the individual.
For a full-credit description, state how individuals are labeled, give the randInt bounds, and explain that values are processed in order. Say that repeats are skipped and more values are generated until the requested sample size of distinct individuals is reached. If asked why the result is an SRS, connect the chance-based selection process to the equal-chance definition of an SRS.
Check Your Understanding
Use the randInt procedure and the stated roster information to answer each question.
- A roster has 45 individuals labeled 1 through 45. Write a randInt command that generates a batch of eight candidate labels.
- A sample of four is needed from labels 1 through 20. The generated values are 6, 11, 6, 20, and 3. Which labels make up the sample, and why is the repeated value handled differently?
- A calculator generates five values for a requested sample of five, but one value appears twice. Does the batch contain five different individuals? What should the sampler do next?
- A roster is labeled 001 through 125. Which command has the correct bounds: \(randInt(1,124,6)\), \(randInt(1,125,6)\), or \(randInt(0,125,6)\)? Explain.
- Why does skipping repeated labels help produce a sample without replacement, and why should the sampler not replace a duplicate with a personally chosen label?