0
0
Pythonprogramming~5 mins

Random data generation in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the random module in Python?
The random module helps generate random numbers and select random items, useful for simulations, games, and testing.
Click to reveal answer
beginner
How do you generate a random integer between 1 and 10 inclusive in Python?
Use random.randint(1, 10). It returns a random integer including both 1 and 10.
Click to reveal answer
beginner
What function would you use to pick a random element from a list?
Use random.choice(your_list) to select one random item from the list.
Click to reveal answer
intermediate
Explain the difference between random.random() and random.uniform(a, b).
random.random() returns a float between 0.0 and 1.0 (including 0.0 but excluding 1.0). random.uniform(a, b) returns a float between a and b, including decimals.
Click to reveal answer
intermediate
Why might you use random.seed() in your program?
To make random results repeatable for testing or debugging by setting a starting point for the random number generator.
Click to reveal answer
Which function generates a random integer between two numbers inclusive?
Arandom.choice(list)
Brandom.random()
Crandom.uniform(a, b)
Drandom.randint(a, b)
What does random.choice() do?
AReturns a random float between 0 and 1
BSelects a random element from a sequence
CGenerates a random integer
DShuffles a list in place
How can you make random results repeatable in Python?
AUse random.randint()
BUse random.shuffle()
CUse random.seed() with a fixed number
DUse random.choice()
Which function returns a random float between 0.0 and 1.0?
Arandom.random()
Brandom.uniform()
Crandom.randint()
Drandom.choice()
What does random.shuffle() do to a list?
ARandomly rearranges the list items in place
BReturns a new sorted list
CSelects a random item
DGenerates a random integer
Describe how to generate a random integer and a random float in Python using the random module.
Think about functions for integers and floats separately.
You got /4 concepts.
    Explain why and how you would use random.seed() in your code.
    Consider when you want the same random output every time.
    You got /4 concepts.