AP Computer Science Principles Flashcards: Random Values

Study Random Values in AP Computer Science Principles with focused flashcards that help you recognize the idea, recall the key rule, and apply it in practice-style prompts.

AP Computer Science Principles

Random Values

0 mastered0 still learning

0% Complete

QUESTION
1/ 58

Which option best describes the sequence produced by a PRNG?

Tap card or press Space to flip

ANSWER

Deterministic and reproducible with the same seed. Mathematical algorithms ensure consistent behavior across runs.

How well did you know it?

Card 1 / 58

What this deck covers

This deck focuses on Random Values, giving you a quick way to review the definitions, rules, and examples that matter most for AP Computer Science Principles.

How to use these flashcards

Work through these flashcards in short sessions. Try to answer each prompt before flipping the card, then revisit any cards you miss until the explanation feels automatic.

All flashcards

Flashcard 1: Which option best describes the sequence produced by a PRNG?

Answer: Deterministic and reproducible with the same seed. Mathematical algorithms ensure consistent behavior across runs.

Flashcard 2: Which method randomizes the order of elements in a list in Python?

Answer: random.shuffle(list). Randomly reorders elements using Fisher-Yates algorithm internally.

Flashcard 3: Find the error: random.uniform(1, 10) gives integers between 1 and 10.

Answer: Correct: Yields floats, not integers. Uniform distribution produces continuous values, not discrete integers.

Flashcard 4: What is the primary difference between PRNG and TRNG?

Answer: PRNGs are algorithm-based; TRNGs are based on physical processes. PRNGs use math; TRNGs use unpredictable physical phenomena.

Flashcard 5: What is a random number generator (RNG)?

Answer: An algorithm that produces a sequence of numbers with no discernible pattern. Uses mathematical algorithms to simulate unpredictable sequences.

Flashcard 6: What is the primary difference between PRNG and TRNG?

Answer: PRNGs are algorithm-based; TRNGs are based on physical processes. PRNGs use math; TRNGs use unpredictable physical phenomena.

Flashcard 7: Which method resets the state of the random number generator in Java?

Answer: setSeed(long seed). Resets internal state to produce new random sequence.

Flashcard 8: Which method resets the state of the random number generator in Java?

Answer: setSeed(long seed). Resets internal state to produce new random sequence.

Flashcard 9: What is the output of Math.random() in Java?

Answer: A double value between 0.0 (inclusive) and 1.0 (exclusive). Standard uniform distribution used in most random calculations.

Flashcard 10: Find the error: Using the same seed always produces different random sequences.

Answer: Correct: It produces the same sequence. Deterministic algorithms always repeat with identical starting conditions.

Flashcard 11: Find the error: random(0,1) generates a number between 0 and 1.

Answer: Correct: Generates either 0 or 1, not a decimal. Random integers are discrete values, not continuous decimals.

Flashcard 12: What is the typical range of a random number generated by rand() in C++?

Answer: 0 to RAND_MAX. RAND_MAX is typically 32767 or larger depending on implementation.

Flashcard 13: Which method randomizes the order of elements in a list in Python?

Answer: random.shuffle(list). Randomly reorders elements using Fisher-Yates algorithm internally.

Flashcard 14: Identify the purpose of random.sample(population, k) in Python.

Answer: Returns a k-length list of unique elements from the population. Sampling without replacement ensures no duplicate elements.

Flashcard 15: What does random.choices(population, weights) do in Python?

Answer: Selects k elements with given weights. Weighted selection allows different probabilities for each element.

Flashcard 16: Identify the purpose of random.sample(population, k) in Python.

Answer: Returns a k-length list of unique elements from the population. Sampling without replacement ensures no duplicate elements.

Flashcard 17: What is the output of Math.random() in Java?

Answer: A double value between 0.0 (inclusive) and 1.0 (exclusive). Standard uniform distribution used in most random calculations.

Flashcard 18: Identify the main function of a seed in random number generation.

Answer: To initialize the random number generator, ensuring reproducibility. Same seed produces identical sequences for testing and debugging.

Flashcard 19: Choose the correct statement about pseudorandom numbers.

Answer: They are generated by a deterministic algorithm. Mathematical formulas create sequences that appear random but are predictable.

Flashcard 20: State the formula for generating a random integer between aa and bb inclusive.

Answer: random(a,b)=a+(rand()%(ba+1))random(a, b) = a + (rand() \, \% \, (b - a + 1)). Modulo operation constrains range to desired integer bounds.

Flashcard 21: Which function returns a random element from a non-empty sequence?

Answer: random.choice(sequence). Works with any sequence type including lists, tuples, strings.

Flashcard 22: Identify the type of random number generator that uses physical processes.

Answer: True random number generator (TRNG). Uses hardware entropy like thermal noise or radioactive decay.

Flashcard 23: Which option best describes the sequence produced by a PRNG?

Answer: Deterministic and reproducible with the same seed. Mathematical algorithms ensure consistent behavior across runs.

Flashcard 24: What does the method random.choice(list) return in Python?

Answer: A randomly selected element from the list. Picks one item randomly from the sequence with equal probability.

Flashcard 25: Find and correct the mistake: Math.random() * 10 gives a number 1-10.

Answer: Correct: Gives a number 0-10. Multiplication scales from [0,1)[0,1) to [0,10)[0,10) range.

Flashcard 26: What does the method random.choice(list) return in Python?

Answer: A randomly selected element from the list. Picks one item randomly from the sequence with equal probability.

Flashcard 27: What is the result of random.randint(5, 5) in Python?

Answer: Always returns 5. Single value range always returns that exact value.

Flashcard 28: What is the purpose of the srand() function in C++?

Answer: Seeds the random number generator. Initializes the random sequence starting point for reproducibility.

Flashcard 29: What does random.choices(population, weights) do in Python?

Answer: Selects k elements with given weights. Weighted selection allows different probabilities for each element.

Flashcard 30: What is the typical range of a random number generated by rand() in C++?

Answer: 0 to RAND_MAX. RAND_MAX is typically 32767 or larger depending on implementation.

Flashcard 31: What is the effect of random.seed() without an argument in Python?

Answer: Seeds generator with current time or system state. Uses entropy from system clock or hardware for unpredictability.

Flashcard 32: Find the error: random(0,1) generates a number between 0 and 1.

Answer: Correct: Generates either 0 or 1, not a decimal. Random integers are discrete values, not continuous decimals.

Flashcard 33: Identify the type of random number generator that uses physical processes.

Answer: True random number generator (TRNG). Uses hardware entropy like thermal noise or radioactive decay.

Flashcard 34: Which Python function generates a random float between 0.0 and 1.0?

Answer: random.random(). Base function for generating uniform floating-point distributions.

Flashcard 35: What is the result of random.randint(1, 10) in Python?

Answer: An integer between 1 and 10 inclusive. Inclusive bounds mean both endpoints can be returned.

Flashcard 36: Identify the main function of a seed in random number generation.

Answer: To initialize the random number generator, ensuring reproducibility. Same seed produces identical sequences for testing and debugging.

Flashcard 37: Which Python function generates a random float between 0.0 and 1.0?

Answer: random.random(). Base function for generating uniform floating-point distributions.

Flashcard 38: What is a random number generator (RNG)?

Answer: An algorithm that produces a sequence of numbers with no discernible pattern. Uses mathematical algorithms to simulate unpredictable sequences.

Flashcard 39: Find and correct the mistake: Math.random() * 10 gives a number 1-10.

Answer: Correct: Gives a number 0-10. Multiplication scales from [0,1)[0,1) to [0,10)[0,10) range.

Flashcard 40: Find the error: random.uniform(1, 10) gives integers between 1 and 10.

Answer: Correct: Yields floats, not integers. Uniform distribution produces continuous values, not discrete integers.

Flashcard 41: Find the error: Using the same seed always produces different random sequences.

Answer: Correct: It produces the same sequence. Deterministic algorithms always repeat with identical starting conditions.

Flashcard 42: Which programming construct is often used to simulate randomness?

Answer: The random number generator function. Built-in functions like rand() or random() provide pseudorandom values.

Flashcard 43: Which function is used to generate a random floating-point number in Python?

Answer: random.uniform(a, b). Generates continuous floating-point values within specified bounds.

Flashcard 44: Which function returns a random element from a non-empty sequence?

Answer: random.choice(sequence). Works with any sequence type including lists, tuples, strings.

Flashcard 45: Choose the correct statement about pseudorandom numbers.

Answer: They are generated by a deterministic algorithm. Mathematical formulas create sequences that appear random but are predictable.

Flashcard 46: Which function is used to generate a random floating-point number in Python?

Answer: random.uniform(a, b). Generates continuous floating-point values within specified bounds.

Flashcard 47: Which programming construct is often used to simulate randomness?

Answer: The random number generator function. Built-in functions like rand() or random() provide pseudorandom values.

Flashcard 48: State the effect of calling random.seed(x) in Python.

Answer: Initializes the random number generator with seed x. Sets starting state for predictable random sequence generation.

Flashcard 49: What type of values does random.randrange(start, stop[, step]) return?

Answer: A random number from the specified range. Similar to range() but returns random value from sequence.

Flashcard 50: State the formula for generating a random integer between aa and bb inclusive.

Answer: random(a,b)=a+(rand()%(ba+1))random(a, b) = a + (rand() \, \% \, (b - a + 1)). Modulo operation constrains range to desired integer bounds.

Flashcard 51: What type of values does random.randrange(start, stop[, step]) return?

Answer: A random number from the specified range. Similar to range() but returns random value from sequence.

Flashcard 52: What is the result of random.randint(1, 10) in Python?

Answer: An integer between 1 and 10 inclusive. Inclusive bounds mean both endpoints can be returned.

Flashcard 53: State the effect of calling random.seed(x) in Python.

Answer: Initializes the random number generator with seed x. Sets starting state for predictable random sequence generation.

Flashcard 54: What is the result of random.randint(5, 5) in Python?

Answer: Always returns 5. Single value range always returns that exact value.

Flashcard 55: Identify the range of numbers produced by Math.random() in Java.

Answer: 0.0 (inclusive) to 1.0 (exclusive). Standard range for most programming language random functions.

Flashcard 56: What is the effect of random.seed() without an argument in Python?

Answer: Seeds generator with current time or system state. Uses entropy from system clock or hardware for unpredictability.

Flashcard 57: What is the purpose of the srand() function in C++?

Answer: Seeds the random number generator. Initializes the random sequence starting point for reproducibility.

Flashcard 58: Identify the range of numbers produced by Math.random() in Java.

Answer: 0.0 (inclusive) to 1.0 (exclusive). Standard range for most programming language random functions.