Fetch
Decode
Explain
Activities
Flashcards
Exam Questions
Revise
Blog
Contact
Login
Login
Menu
Activities
Flashcards
Exam Questions
Revise
Blog
Contact
Login
Qualifications
OCR GCSE Computer Science
2.2 Programming Fundamentals
Random Library
Card
1
of
16
0
got it
0
still learning
Question
Evil question
Tap
Click or press space
to see the answer
Answer
Still learning
Got it
Turn over
Shuffle
0%
Round complete
Go again with the ones I'm still learning
Start the whole set again
Choose another set
All 16 cards in this set
Which term describes a pre-written collection of code that a program can bring in to add extra features, such as the one that creates random numbers?
Library
What is the name for creating values in a program that cannot be predicted and are different each time the program runs?
Random number generation
What is meant by random.randint(1, 6)?
A call that returns a whole number from 1 to 6, including both ends
What is meant by storing the value of random.randint(1, 6) in a variable?
Keeping the number so the same value can be used again later
Which line must appear at the top of a Python program so that random.randint can be used?
Import random
What values does random.random() return?
A real number from 0.0 up to but not including 1.0
A program needs to store a random real number from 5.0 up to but not including 10.0 in a variable called value. Which line should it use?
Value = 5 + random.random() * 5
A game rolls two separate dice with random.randint(1, 6) each and adds them. How does this differ from one call of random.randint(2, 12)?
Totals near 7 are more likely with two separate dice
Which line gives a value that could represent the two possible outcomes of a coin toss?
Coin = random.randint(0, 1)
A program calls random.randint(1, 6) but does not start with import random. What happens?
A NameError is reported when the line is run
A program picks six lottery numbers using six separate calls of random.randint(1, 49). Why is this not suitable for a real lottery?
The same number can be picked more than once
A program stores random.randint(1, 100) in a variable and then prints the value doubled. What could the output be?
A whole number from 2 to 200
Which of these programs needs to produce values that are different each time it runs?
A program that rolls dice for a game
How many times should import random appear in a program that creates random numbers in several places?
Once, at the top of the program
This program rolls two dice. Which totals can be printed?
Any whole number from 2 to 12
Why must a program import the random library before random.randint can be used?
The function is held in the library, not built in