All flashcards
Flashcard 1: 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 2: 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 3: 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 4: 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 5: 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 6: 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 7: 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 8: 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 9: 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 10: 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 11: 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 12: 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 13: 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 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: 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 16: 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 17: 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) to [0,10) range.
Flashcard 18: What is the result of random.randint(5, 5) in Python?
Answer: Always returns 5. Single value range always returns that exact value.
Flashcard 19: 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 20: 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 21: 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 22: 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 23: 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 24: 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 25: State the formula for generating a random integer between a and b inclusive.
Answer: random(a,b)=a+(rand()%(b−a+1)). Modulo operation constrains range to desired integer bounds.
Flashcard 26: 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 27: 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 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: 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 30: 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.