Random Flashcards

1
Q

How do you import the random library?

A

import random

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Generate random numbers between 0 and 1

A

random.random()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Obtain a random integer between 2 and 30

A

random.randit(2, 30)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How would you shuffle between the cards stored in the variable “deck”?

A

random.shuffle(deck)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How would you sample 5 cards from the variable “deck”?

A

random.sample(deck, k = 5)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly