wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

J277 - 2.2 - Random Number Generation

Total questions: 8

Worksheet time: 4mins

Name
Class
Date
1.

What is the purpose of random number generation in programming?

a)

To create predictable sequences of numbers

b)

To simulate randomness in applications

c)

To sort numbers in ascending order

d)

To convert numbers to strings

2.

Which Python module is commonly used for generating random numbers?

a)

math

b)

random

c)

statistics

d)

numpy

3.

How do you generate a random integer between 1 and 10 using the random module in Python?

a)

`random.random(1, 10)`

b)

`random.randint(1, 10)`

c)

`random.range(1, 10)`

d)

`random.int(1, 10)`

4.

Which function from the random module would you use to select a random element from a list?

a)

`random.choice()`

b)

`random.select()`

c)

`random.pick()`

d)

`random.element()`

5.

If you have a list `fruits = ['apple', 'banana', 'cherry', 'date']`, which of the following code snippets will randomly select a fruit from the list?

a)

`random.choice(fruits)`

b)

`random.randint(fruits)`

c)

`random.random(fruits)`

d)

`random.select(fruits)`

6.

Which of the following functions from the random module can be used to shuffle a list in place?

a)

`random.shuffle()`

b)

`random.mix()`

c)

`random.scramble()`

d)

`random.reorder()`

7.

How can you generate a random floating-point number between 0 and 1 using the random module?

a)

`random.uniform(0, 1)`

b)

`random.random()`

c)

`random.float()`

d)

`random.rand()`

8.

Which function from the random module would you use to generate a random sample of 3 elements from a list `numbers = [1, 2, 3, 4, 5, 6]`?

a)

`random.choice(numbers, 3)`

b)

`random.sample(numbers, 3)`

c)

`random.select(numbers, 3)`

d)

`random.pick(numbers, 3)`