0% found this document useful (0 votes)
11 views5 pages

Here

Uploaded by

princethakan9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views5 pages

Here

Uploaded by

princethakan9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Here’s the updated slide structure with animations explicitly included for questions, as per your

request:

Slide 1: Title Slide

 Title: Random Function

 Subtitle: Unveiling the Power of Randomness in Programming

Slide 2: Introduction to Random Function

 Definition:
A random function generates unpredictable outputs, commonly used in simulations, games,
and testing.

 Key Features:

o Produces random numbers or values.

o Offers a variety of functions for specific use cases (e.g., integers, floats, list
elements).

 Example: Rolling dice, shuffling cards, or picking a random item.

Slide 3: Random Module in Python

 Importing the Module:


Before using random functions, import the random module:

 import random

Slide 4: Overview of Random Functions

Function Description Example

Generates a random float between random.random() → 0.572 (example


random.random()
0 and 1 (exclusive). output)

Returns a random integer between random.randint(1, 10) → 7 (example


random.randint(a, b)
a and b (inclusive). output)

random.uniform(a, Returns a random float between a random.uniform(5.5, 9.5) → 6.3 (example


b) and b. output)

Selects a random element from a random.choice(['red', 'blue', 'green']) →


random.choice(seq)
sequence (e.g., list, string). 'blue' (example output)

Randomly rearranges elements in a random.shuffle([1, 2, 3]) → [3, 1, 2]


random.shuffle(lst)
list. (example output)
Slide 5: Usage of Random Functions

 Applications:

1. Games (e.g., shuffling cards, randomizing moves).

2. Simulations (e.g., weather predictions).

3. Cryptography (e.g., random key generation).

4. Testing (e.g., generating random test data).

 Example Program:

 import random

 print(random.randint(1, 6)) # Simulates a dice roll

 print(random.choice(['head', 'tail'])) # Simulates a coin toss

Slide 6: Question 1

Question:
What will random.randint(1, 5) return?

 Animation: The question pops out first.

Options:

 (A) Any integer between 0 and 5.

 (B) Any integer between 1 and 4.

 (C) Any integer between 1 and 5.

 (D) Any integer between 0 and 4.

 Animation: Options fade in sequentially, one at a time.

Answer:
(C) Any integer between 1 and 5.

 Animation: Answer slides in after all options are displayed.

Explanation:
The randint() function includes both boundaries, so the possible outputs are 1, 2, 3, 4, or 5.

 Animation: Explanation fades in at the bottom.

Slide 7: Question 2

Question:
What will the following code output?
import random

print(random.choice(['apple', 'banana', 'cherry']))

 Animation: The question pops out first.

Options:

 (A) apple

 (B) banana

 (C) cherry

 (D) Any one of the above

 Animation: Options fade in sequentially, one at a time.

Answer:
(D) Any one of the above.

 Animation: Answer slides in after all options are displayed.

Explanation:
The choice() function randomly selects one element from the list, so the output can be either apple,
banana, or cherry.

 Animation: Explanation fades in at the bottom.

Slide 8: Question 3

Question:
Which function generates a random float between two numbers, aa and bb?

 Animation: The question pops out first.

Options:

 (A) random()

 (B) randint(a, b)

 (C) uniform(a, b)

 (D) shuffle()

 Animation: Options fade in sequentially, one at a time.

Answer:
(C) uniform(a, b)

 Animation: Answer slides in after all options are displayed.

Explanation:
The uniform(a, b) function generates a random float within the range [a,b][a, b], including the
boundaries.
 Animation: Explanation fades in at the bottom.

Slide 9: Question 4

Question:
What will random.shuffle() do to a list?

 Animation: The question pops out first.

Options:

 (A) Sort the list in ascending order.

 (B) Sort the list in descending order.

 (C) Rearrange the list in random order.

 (D) Remove duplicates from the list.

 Animation: Options fade in sequentially, one at a time.

Answer:
(C) Rearrange the list in random order.

 Animation: Answer slides in after all options are displayed.

Explanation:
The shuffle() function rearranges the elements of the list randomly. It modifies the list in place.

 Animation: Explanation fades in at the bottom.

Slide 10: Question 5

Question:
What will random.random() return?

 Animation: The question pops out first.

Options:

 (A) A random float between 0 and 1.

 (B) A random integer between 0 and 1.

 (C) A random float between 1 and 10.

 (D) A random integer between 1 and 10.

 Animation: Options fade in sequentially, one at a time.

Answer:
(A) A random float between 0 and 1.

 Animation: Answer slides in after all options are displayed.


Explanation:
The random() function always generates a float between 0 (inclusive) and 1 (exclusive).

 Animation: Explanation fades in at the bottom.

Slide 11: Thank You Slide

 Closing note: "Unlock randomness for endless possibilities in programming!"

Let me know if you'd like me to create this PowerPoint file for you!

You might also like