Random Flashcards
1
Q
How do you import the random library?
A
import random
2
Q
Generate random numbers between 0 and 1
A
random.random()
3
Q
What does the random.uniform() function do?
A
It gets random floats from the uniform distribution, in which the probability of getting elements is the same
4
Q
Obtain a random integer between 2 and 30
A
random.randit(2, 30)
5
Q
Create a list of five grocery store items and then randomly pick one of the items.
A
groceries = [“item1”, “item2”, “item3”, “item4”, “item5”]
random.choice(groceries)
6
Q
How would you shuffle between the cards stored in the variable “deck”?
A
random.shuffle(deck)
7
Q
How would you sample 5 cards from the variable “deck”?
A
random.sample(deck, k = 5)